Android:java.lang.OutOfMemoryError: Failed to allocate a 23970828 byte allocation with 2097152 free bytes and 2MB until OOM

前端 未结 30 2054
暗喜
暗喜 2020-11-21 07:33

I want to show the Bitmap image in ImageView from sd card which is stored already. After run my application is crash and getting Ou

30条回答
  •  甜味超标
    2020-11-21 07:48

    Resize your image before setup to ImageView like this:

    Bitmap.createScaledBitmap(_yourImageBitmap, _size, _size, false);
    

    where size is actual size of ImageView. You can reach size by measuring:

    imageView.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    

    and use next size imageView.getMeasuredWidth() and imageView.getMeasuredHeight() for scaling.

提交回复
热议问题