Compose-Cropper icon indicating copy to clipboard operation
Compose-Cropper copied to clipboard

Fatal Exception: java.lang.RuntimeException Canvas: trying to draw too large(192000000bytes) bitmap

Open mehul4795 opened this issue 1 year ago • 2 comments

I am using Compose-Cropper in one of my apps. I am receiving the below error for many users. The Bitmap size mentioned is random but usually large.

Fatal Exception: java.lang.RuntimeException
Canvas: trying to draw too large(201326592bytes) bitmap.
android.graphics.RecordingCanvas.throwIfCannotDraw (RecordingCanvas.java:287)

androidx.compose.ui.graphics.drawscope.DrawScope.drawImage-AZ2fEMs$default (DrawScope.kt:510)
com.smarttoolfactory.cropper.draw.ImageDrawCanvasKt$ImageDrawCanvas$1.invoke (ImageDrawCanvas.kt:26)
com.smarttoolfactory.cropper.draw.ImageDrawCanvasKt$ImageDrawCanvas$1.invoke (ImageDrawCanvas.kt:21)
androidx.compose.ui.draw.DrawBackgroundModifier.draw (DrawModifier.kt:116)

com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1049)

Is there any workaround that can be implemented to prevent this exception?

mehul4795 avatar Oct 03 '23 10:10 mehul4795

Try to get a scaled-down version of the bitmap from the device as described here https://developer.android.com/topic/performance/graphics/load-bitmap. You might find more specific information on how to load large bitmaps on stack overflow

anton-begeima-okcupid avatar Oct 18 '23 13:10 anton-begeima-okcupid

In my app, due to specific flow I am scaling the bitmap but at the later stage after the image is cropped using the Cropper. As you suggested, I think I should scale the bitmap earlier. Anyways, thanks :)

mehul4795 avatar Oct 20 '23 13:10 mehul4795