Hi I am creating Bitmap object and using in canvas, like below code
Bitmap result = Bitmap.createBitmap(loadedImage.getWidth(), loadedImage.getHeight(), Config.ARGB_8888);
Canvas mCanvas = new Canvas(result);
Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT));
mCanvas.drawBitmap(blurBitmap, 0, 0, null);
mCanvas.drawBitmap(loadedImage, 0, 0, paint);
paint.setXfermode(null);
ivBlur.setImageBitmap(result);
// now i don't want Bitmap "result" so I am recycling it
if (result != null && !result.isRecycled())
result.recycle();
}
But from above code I am getting an error like
trying to use recycled bitmap android
How to fix "canvas: trying to use a recycled bitmap error"?
trying to use a recycled bitmap android.graphics.Bitmap
Canvas: trying to use a recycled bitmap android.graphics.Bitmap in android
If I don't write last three lines it is working perfect, It may be because Canvas is using Bitmap "result" object and I am recycling "result"
Because of this bitmap is taking huge space, I have to recycle this bitmap otherwise I will get
java.lang.OutofMemoryError: bitmap size exceeds VM budget.
So does anyone know how can I get that, "Canvas has used bitmap object and now I can recycle result object".