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

前端 未结 30 2175
暗喜
暗喜 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:46

    Bitmap image =((BitmapDrawable)imageView1.getDrawable()).getBitmap();
    
    ByteArrayOutputStream byteArrayOutputStream=new ByteArrayOutputStream();
    
    image.compress(Bitmap.CompressFormat.JPEG,50/100,byteArrayOutputStream);
    

    50/100 if one uses 100 then original resolution can stopped the Apps for out of memory.

    if 50 or less than 100 this will be 50% or less than 100 resolution so this will prevent from out of memory problem

提交回复
热议问题