OOM解决办法

手动进行垃圾回收   调用bitmap.recycle() 或者System.gc();

If you use them for fit-in screen display only, just scale them to the 
screen-size. You don't need any bigger. 

1. Figure out the actual width and height of the image 
(inJustDecodeBounds = true) 
2. When actually loading the pic, downsample (inSampleSize > 1) so 
that the resulting image fits the screen as good as possible (for best 
result, make the loaded image a bit bigger than the screen instead of 
a bit smaller). Also, the values of inSampleSize work best across most 
phones when its value is a power of 2 (2, 4, 8, etc) 
3. Then scale the image (down) a bit further to exactly fit the 
screen. 
E.g. say your screen is 800x400. Your image is 2048x1536. Then 
downsample the image (inSampleSize = 2) --> Loaded image is 1024x768. 
Then scale the downsampled image by 52.08333% --> a bitmap of 533x400 
pixels. Cache this image. Still, be careful not to cache too many 
images. 
On Feb 8, 9:48 am, Samuh <samuh.va ...@gmail.com> wrote:

 

------------------------------------------------------------------------------------

 

  1. private Bitmap decodeFile(File f){
  2.     Bitmap b = null;
  3.     try {
  4.         //Decode image size
  5.         BitmapFactory.Options o = new BitmapFactory.Options();
  6.         o.inJustDecodeBounds = true;
  7.         BitmapFactory.decodeStream(new FileInputStream(f), null, o);
  8.         int scale = 1;
  9.         if (o.outHeight > IMAGE_MAX_SIZE || o.outWidth > IMAGE_MAX_SIZE) {
  10.             scale = Math.pow(2, (int) Math.round(Math.log(IMAGE_MAX_SIZE / (double) Math.max(o.outHeight, o.outWidth)) / Math.log(0.5)));
  11.         }
  12.         //Decode with inSampleSize
  13.         BitmapFactory.Options o2 = new BitmapFactory.Options();
  14.         o2.inSampleSize = scale;
  15.         b = BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
  16.     } catch (FileNotFoundException e) {
  17.     }
  18.     return b;
  19. }
复制代码


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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值