首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

OOM解决方法

2013-03-01 
OOM解决办法private Bitmap decodeFile(File f){? ? Bitmap b null? ? try {? ?? ???//Decode image si

OOM解决办法

  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

热点排行