我们在kony中使用android ffi将图像制作成圆形。得到这个
Log.d("ANDRO_ASYNC",String.format("catch Out Of Memory error"))
应用程序崩溃时出现以下错误日志: 抛出OutOfMemoryError"无法分配带有5499006个空闲字节的16793702字节分配和5MB直到OOM"试图给bitmap.recycle();但也是一样的错误。
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"
我们得到问题的代码:
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 "";
}
}
}