OutOfMemoryError getting while converting an image to circular shaped one

58 views Asked by At

We are using an android ffi in kony for making an image into circular shape. Getting this

Log.d("ANDRO_ASYNC",String.format("catch Out Of Memory error"))

App is crashing with the below error log: Throwing OutOfMemoryError "Failed to allocate a 16793702 byte allocation with 5499006 free bytes and 5MB until OOM" Tried to give bitmap.recycle(); also but still same error.

Throwing OutOfMemoryError "Failed to allocate a 16793702 byte allocation with 5499006 free bytes and 5MB until OOM"
12-29 15:25:51.631: W/System.err(22324): java.lang.OutOfMemoryError: Failed to allocate a 16793702 byte allocation with 5499006 free bytes and 5MB until OOM
12-29 15:25:51.641: W/System.err(22324):    at java.io.ByteArrayOutputStream.expand(ByteArrayOutputStream.java:91)
12-29 15:25:51.641: W/System.err(22324):    at java.io.ByteArrayOutputStream.write(ByteArrayOutputStream.java:201)
12-29 15:25:51.641: W/System.err(22324):    at android.graphics.Bitmap.nativeCompress(Native Method)
12-29 15:25:51.641: W/System.err(22324):    at android.graphics.Bitmap.compress(Bitmap.java:1283)
12-29 15:25:51.641: W/System.err(22324):    at inducesmile.com.androidcircularimageview.MainActivity.bitmapToBase64(MainActivity.java:37)
12-29 15:25:51.641: W/System.err(22324):    at inducesmile.com.androidcircularimageview.MainActivity.testStart(MainActivity.java:23)
12-29 15:25:51.641: W/System.err(22324):    at com.konylabs.ffi.N_convertImage$ImageConvertion.testStart(N_convertImage.java:128)
12-29 15:25:51.641: W/System.err(22324):    at com.konylabs.ffi.N_convertImage$ImageConvertion.execute(N_convertImage.java:96)
12-29 15:25:51.641: W/System.err(22324):    at com.konylabs.vm.Function.executeJS(Native Method)
12-29 15:25:51.641: W/System.err(22324):    at com.konylabs.vm.Function.execute(Unknown Source)
12-29 15:25:51.641: W/System.err(22324):    at com.konylabs.vmintf.KonyJavaScriptVM.a(Unknown Source)
12-29 15:25:51.641: W/System.err(22324):    at com.konylabs.android.G.handleMessage(Unknown Source)
12-29 15:25:51.641: W/System.err(22324):    at android.os.Handler.dispatchMessage(Handler.java:102)
12-29 15:25:51.641: W/System.err(22324):    at android.os.Looper.loop(Looper.java:145)
12-29 15:25:51.641: W/System.err(22324):    at com.konylabs.android.F.run(Unknown Source)
12-29 15:25:51.641: D/skia(22324): ------- write threw an exception
12-29 15:25:51.641: I/try----->>>(22324): bitmapToBase66
12-29 15:25:51.661: I/art(22324): Clamp target GC heap from 138MB to 128MB
12-29 15:25:51.661: I/art(22324): Alloc partial concurrent mark sweep GC freed 8(8KB) AllocSpace objects, 0(0B) LOS objects, 4% free, 122MB/128MB, paused 783us total 11.659ms
12-29 15:25:51.681: I/art(22324): Clamp target GC heap from 138MB to 128MB
12-29 15:25:51.681: I/art(22324): Alloc concurrent mark sweep GC freed 9(384B) AllocSpace objects, 0(0B) LOS objects, 4% free, 122MB/128MB, paused 838us total 20.786ms
12-29 15:25:51.681: I/art(22324): Forcing collection of SoftReferences for 8MB allocation
12-29 15:25:51.701: I/art(22324): Clamp target GC heap from 138MB to 128MB
12-29 15:25:51.701: I/art(22324): Alloc concurrent mark sweep GC freed 15(672B) AllocSpace objects, 0(0B) LOS objects, 4% free, 122MB/128MB, paused 817us total 22.457ms
12-29 15:25:51.701: E/art(22324): Throwing OutOfMemoryError "Failed to allocate a 8392761 byte allocation with 5506606 free bytes and 5MB until OOM"

code where we get the issue:

public class MainActivity
{

public String testStart(String base64)
{
    Log.i("testart-->>", "latest");
    String base = "";
    byte[] imageAsBytes = Base64.decode(base64.getBytes(), Base64.DEFAULT);
     Bitmap bitmap = BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length);

    Bitmap circularBitmap = ImageConverter.getRoundedCornerBitmap(bitmap, 100);
    Log.i("testart-->>", "oustode");
    base = bitmapToBase64(circularBitmap);
    return base;

}
private String bitmapToBase64(Bitmap bitmap)
{
    try{

        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();

        bitmap.compress(Bitmap.CompressFormat.PNG, 5, byteArrayOutputStream);
            byte[] byteArray = byteArrayOutputStream.toByteArray();

        System.gc();

        return Base64.encodeToString(byteArray, Base64.DEFAULT);
    }catch(OutOfMemoryError E){
        Log.d("ANDRO_ASYNC",String.format("catch Out Of Memory error"));
        //      E.printStackTrace();
        System.gc();

        return "";
    }
}
}
0

There are 0 answers