java.lang.OutOfMemoryError BitmapFactory.nativeDecodeAsset()

前端 未结 2 816
南笙
南笙 2021-01-05 02:08

Hi i am creating an app about traffic signs. traffic signs are in .png format. some of them I am showing in horizontalscrollview. But when try to open activities , I get thi

相关标签:
2条回答
  • 2021-01-05 03:10

    Use sampling to read bitmap. May be error occurred due to memory leaks.

    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inSampleSize = 4;
    
    Bitmap bitmap=BitmapFactory.decodeFile(path,options);
    
    0 讨论(0)
  • 2021-01-05 03:12

    The "bitmap size exceeds VM budget" error is actually in the native graphics library (Skia). It is a tad confusing as the problem is really that Skia has run out of memory in the native heap for bitmap data. See BitmapFactory OOM driving me nuts for background. To get round this, you will have to look carefully at your bitmap usage

    • making sure that you do not leave bitmap references floating
    • doing a recycle / null onn bitmaps as they become free (this appears to help).
    0 讨论(0)
提交回复
热议问题