Open kancic opened 9 years ago
Hi r1m,
i'm trying your solution but i get this exception: java.lang.RuntimeException: Canvas: trying to use a recycled bitmap android.graphics.Bitmap@7a2da54
Have you found other solution?
Thanks
No, sorry. This solution worked for me.
I applies this changes:
private void createMaskCanvas(int width, int height, int oldw, int oldh) {
boolean sizeChanged = width != oldw || height != oldh;
boolean isValid = width > 0 && height > 0;
if(isValid && (maskCanvas == null || sizeChanged)) {
maskCanvas = new Canvas();
Bitmap oldBitmap = maskBitmap;
maskBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
if (oldBitmap != null && oldBitmap != maskBitmap && !oldBitmap.isRecycled()) oldBitmap.recycle();
maskCanvas.setBitmap(maskBitmap);
maskPaint.reset();
paintMaskCanvas(maskCanvas, maskPaint, width, height);
drawableCanvas = new Canvas();
oldBitmap = drawableBitmap;
drawableBitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
if (oldBitmap != null && oldBitmap != drawableBitmap && !oldBitmap.isRecycled()) oldBitmap.recycle();
drawableCanvas.setBitmap(drawableBitmap);
drawablePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
invalidated = true;
}
}
And this:
@Override
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
if (maskBitmap != null && !maskBitmap.isRecycled()) maskBitmap.recycle();
if (drawableBitmap != null && !drawableBitmap.isRecycled()) drawableBitmap.recycle();
}
It's possible I missed something because I have a very simple use case. I only show one shape image view at the time so maybe if you use something more complex my code doesn't work.
Did anyone solve this memory issue?
I am getting the same issue, i just used on a single imageview in my whole project!
Hello,
First of all great library, thank you. I think you have a memory leak in your code that is causing OutOfMemory errors. I have added these lines of code in the PorterImageView class and they are gone now. I'm not really sure if they are all needed.