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

前端 未结 30 2136
暗喜
暗喜 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 08:10

    If uploading an image, try reducing the image quality, which is the second parameter of the Bitmap. This was the solution in my case. Previously it was 90, then I tried with 60 (as it is in the code below now).

    Bitmap yourSelectedImage = BitmapFactory.decodeStream(imageStream);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    finalBitmap.compress(Bitmap.CompressFormat.JPEG,60,baos);
    byte[] b = baos.toByteArray();
    

提交回复
热议问题