OOM解决方法
OOM解决办法private Bitmap decodeFile(File f){? ? Bitmap b null? ? try {? ?? ???//Decode image si
OOM解决办法
- private Bitmap decodeFile(File f){
- ? ? Bitmap b = null;
- ? ? try {
- ? ?? ???//Decode image size
- ? ?? ???BitmapFactory.Options o = new BitmapFactory.Options();
- ? ?? ???o.inJustDecodeBounds = true;
- ? ?? ???BitmapFactory.decodeStream(new FileInputStream(f), null, o);
- ? ?? ???int scale = 1;
- ? ?? ???if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
- ? ?? ?? ?? ?scale = Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
- ? ?? ???}
- ? ?? ???//Decode with inSampleSize
- ? ?? ???BitmapFactory.Options o2 = new BitmapFactory.Options();
- ? ?? ???o2.inSampleSize = scale;
- ? ?? ???b = BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
- ? ? } catch (FileNotFoundException e) {
- ? ? }
- ? ? return b;
- }
复制代码
Reference :?
? ?? ?? ???1.Handling big Bitmaps? ?? ?? ???? ?? ?? ?? ??http://groups.google.com/group/a ... 1a63ad2?lnk=gst&;q=samu
? ?? ?? ???2.?'bitmap size exceeds VM budget' if Activity is restarted [includes test demo!]
? ?? ?? ?? ?http://code.google.com/p/android/issues/detail?id=8488
? ?? ?? ???3.?How to... if you want to create and destroy the Bitmaps too frequently...
http://mobi-solutions.blogspot.c ... -to-create-and.html??? ?? ?? ???? ?? ?? ? 4.Handling large Bitmaps
? ?? ?? ?? ?http://stackoverflow.com/questions/2220949/handling-large-bitmaps