glide icon indicating copy to clipboard operation
glide copied to clipboard

v4.10.0 transform() -> java.lang.RuntimeException: Canvas: trying to draw too large bitmap.

Open anhduy5689h opened this issue 4 years ago • 7 comments

GlideApp.with(imageView) .load(byteArray) .transform(RoundedCorners(20)) .into(imageView) I only want to load a small image: example: width: 1900, height: 50. java.lang.RuntimeException: Canvas: trying to draw too large(206507928bytes) bitmap. at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:281) at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:91) at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:548) at android.widget.ImageView.onDraw(ImageView.java:1434) at android.view.View.draw(View.java:23187) at android.view.View.updateDisplayListIfDirty(View.java:22062) at android.view.View.draw(View.java:22917) at android.view.ViewGroup.drawChild(ViewGroup.java:5230) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987) at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2023) at android.view.View.draw(View.java:23190) at android.view.View.updateDisplayListIfDirty(View.java:22062) at android.view.View.draw(View.java:22917) at android.view.ViewGroup.drawChild(ViewGroup.java:5230) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987) at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2023) at android.view.View.updateDisplayListIfDirty(View.java:22048) at android.view.View.draw(View.java:22917) at android.view.ViewGroup.drawChild(ViewGroup.java:5230) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987) at android.view.View.updateDisplayListIfDirty(View.java:22048) at android.view.View.draw(View.java:22917) at android.view.ViewGroup.drawChild(ViewGroup.java:5230) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987) at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:2023) at android.view.View.updateDisplayListIfDirty(View.java:22048) at android.view.View.draw(View.java:22917) at android.view.ViewGroup.drawChild(ViewGroup.java:5230) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987) at android.view.View.updateDisplayListIfDirty(View.java:22048) at android.view.View.draw(View.java:22917) at android.view.ViewGroup.drawChild(ViewGroup.java:5230) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987) at android.view.View.updateDisplayListIfDirty(View.java:22048) at android.view.View.draw(View.java:22917) at android.view.ViewGroup.drawChild(ViewGroup.java:5230) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987) at android.view.View.updateDisplayListIfDirty(View.java:22048) at android.view.View.draw(View.java:22917) at android.view.ViewGroup.drawChild(ViewGroup.java:5230) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987) at android.view.View.updateDisplayListIfDirty(View.java:22048) at android.view.View.draw(View.java:22917) at android.view.ViewGroup.drawChild(ViewGroup.java:5230) at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4987) at android.view.View.draw(View.java:23190) at com.android.internal.policy.DecorView.draw(DecorView.java:1154) at android.view.View.updateDisplayListIfDirty(View.java:22062) at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:588) at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:594) at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:667) at android.view.ViewRootImpl.draw(ViewRootImpl.java:4296) at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4080) at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3348) at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2225) at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9126) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:999) at android.view.Choreographer.doCallbacks(Choreographer.java:797) at android.view.Choreographer.doFrame(Choreographer.java:732) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:984) at android.os.Handler.handleCallback(Handler.java:883) 2021-01-29 19:27:22.276 29984-29984/com.example.test E/AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:100) at android.os.Looper.loop(Looper.java:237) at android.app.ActivityThread.main(ActivityThread.java:8167) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:496) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1100) 2021-01-29 19:27:22.280 29984-29984/com.example.test E/PlusExceptionHandler: throwable Canvas: trying to draw too large(206507928bytes) bitmap.

anhduy5689h avatar Jan 29 '21 12:01 anhduy5689h

I meet same problem when image width is very short and set corner。

        Glide.with(binding.image)
            .load("https://qiance.qianfanyun.com/admin_FgsPPk1D-MiMOCNoSd6V4yO6ql20.jpg?imageslim|imageMogr2/format/png/thumbnail/!1x690r/gravity/Center/crop/1x690/interlace/1")
            .transform(RoundedCorners(8))
            .into(binding.image)
    Process: com.qianfan.glidetest, PID: 29852
    java.lang.RuntimeException: Canvas: trying to draw too large(1552500000bytes) bitmap.
        at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:285)
        at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:127)
        at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:555)
        at android.widget.ImageView.onDraw(ImageView.java:1444)
        at android.view.View.draw(View.java:22528)
        at android.view.View.updateDisplayListIfDirty(View.java:21389)
        at android.view.View.draw(View.java:22254)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4541)
        at androidx.coordinatorlayout.widget.CoordinatorLayout.drawChild(CoordinatorLayout.java:1277)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
        at android.view.View.updateDisplayListIfDirty(View.java:21380)
        at android.view.View.draw(View.java:22254)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4541)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
        at android.view.View.updateDisplayListIfDirty(View.java:21380)
        at android.view.View.draw(View.java:22254)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4541)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
        at android.view.View.updateDisplayListIfDirty(View.java:21380)
        at android.view.View.draw(View.java:22254)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4541)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
        at android.view.View.updateDisplayListIfDirty(View.java:21380)
        at android.view.View.draw(View.java:22254)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4541)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
        at android.view.View.updateDisplayListIfDirty(View.java:21380)
        at android.view.View.draw(View.java:22254)
        at android.view.ViewGroup.drawChild(ViewGroup.java:4541)
        at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4302)
        at android.view.View.draw(View.java:22538)
        at com.android.internal.policy.DecorView.draw(DecorView.java:848)
        at android.view.View.updateDisplayListIfDirty(View.java:21389)
        at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:559)
        at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:565)
        at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:647)
        at android.view.ViewRootImpl.draw(ViewRootImpl.java:4417)
        at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4144)
        at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3391)
        at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2182)
        at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8730)
        at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1352)
        at android.view.Choreographer.doCallbacks(Choreographer.java:1149)
        at android.view.Choreographer.doFrame(Choreographer.java:1049)
        at android.view.Choreographer$FrameHandler.handleMessage(Choreographer.java:1275)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:233)
        at android.app.ActivityThread.main(ActivityThread.java:8010)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:631)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:978)

TokenYc avatar Sep 07 '21 03:09 TokenYc

Any update? I meet the same crash with small image when i use glide-compose.

                                 "width": 760,
				"height": 58,

below image is empty blank 760x58 image. BvLC8BEpuWjiG0FntRM1fTOi

cuichanghao avatar May 28 '24 03:05 cuichanghao

any update? I meet the same crash when tried to load image and using override(width, height)

image: ian-custom-kosong

val option = RequestOptions()
    .dontTransform().diskCacheStrategy(DiskCacheStrategy.DATA)
    .override(width, height)
    .placeholder(R.drawable.ic_launcher_background)
  Glide.with(this)
    .load(url)
    .apply(option)
    .into(imageView)

crash log:

    Process: id.example.testrvcrashedimage, PID: 27779
    java.lang.RuntimeException: Canvas: trying to draw too large(105213240bytes) bitmap.
  atandroid.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:266)
  atandroid.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:94)
  atandroid.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:549)
  atandroid.widget.ImageView.onDraw(ImageView.java:1446)
  atandroid.view.View.draw(View.java:23889)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22756)
  atandroid.view.View.draw(View.java:23620)
  atandroid.view.ViewGroup.drawChild(ViewGroup.java:4556)
  atandroid.view.ViewGroup.dispatchDraw(ViewGroup.java:4317)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22747)
  atandroid.view.View.draw(View.java:23620)
  atandroid.view.ViewGroup.drawChild(ViewGroup.java:4556)
  atandroidx.recyclerview.widget.RecyclerView.drawChild(RecyclerView.java:5204)
  atandroid.view.ViewGroup.dispatchDraw(ViewGroup.java:4317)
  atandroid.view.View.draw(View.java:23892)
  atandroidx.recyclerview.widget.RecyclerView.draw(RecyclerView.java:4603)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22756)
  atandroid.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4540)
  atandroid.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4513)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22712)
  atandroid.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4540)
  atandroid.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4513)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22712)
  atandroid.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4540)
  atandroid.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4513)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22712)
  atandroid.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4540)
  atandroid.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4513)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22712)
  atandroid.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4540)
  atandroid.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4513)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22712)
  atandroid.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4540)
  atandroid.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4513)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22712)
  atandroid.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4540)
  atandroid.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4513)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22712)
  atandroid.view.ViewGroup.recreateChildDisplayList(ViewGroup.java:4540)
  atandroid.view.ViewGroup.dispatchGetDisplayList(ViewGroup.java:4513)
  atandroid.view.View.updateDisplayListIfDirty(View.java:22712)
  atandroid.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:694)
  atandroid.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:700)
  atandroid.view.ThreadedRenderer.draw(ThreadedRenderer.java:798)
  atandroid.view.ViewRootImpl.draw(ViewRootImpl.java:4939)
  atandroid.view.ViewRootImpl.performDraw(ViewRootImpl.java:4643)
  atandroid.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3822)
  atandroid.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2465)
  atandroid.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:9305)
  atandroid.view.Choreographer$CallbackRecord.run(Choreographer.java:1339)
  atandroid.view.Choreographer$CallbackRecord.run(Choreographer.java:1348)
  atandroid.view.Choreographer.doCallbacks(Choreographer.java:952)
  atandroid.view.Choreographer.doFrame(Choreographer.java:882)
  atandroid.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1322)
  atandroid.os.Handler.handleCallback(Handler.java:958)
  atandroid.os.Handler.dispatchMessage(Handler.java:99)
  atandroid.os.Looper.loopOnce(Looper.java:205)
  atandroid.os.Looper.loop(Looper.java:294)
  atandroid.app.ActivityThread.main(ActivityThread.java:8177) 
  atjava.lang.reflect.Method.invoke(Native Method)
  atcom.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
  atcom.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)

hahn avatar Jul 24 '24 04:07 hahn

we can add .fitCenter() to perevent crash

val option = RequestOptions()
    .dontTransform().diskCacheStrategy(DiskCacheStrategy.DATA)
    .override(width, height).fitCenter()
    .placeholder(R.drawable.ic_launcher_background)
  Glide.with(this)
    .load(url)
    .apply(option)
    .into(imageView)

hahn avatar Jul 25 '24 03:07 hahn

related: https://github.com/bumptech/glide/issues/4485

cuichanghao avatar Jul 26 '24 02:07 cuichanghao

its happen when is set aspectRatio.

cuichanghao avatar Jul 26 '24 02:07 cuichanghao

It get the same crash on an image whose aspect ratio is 1:18 – it's extremely wide.

Using the fixCenter workaround described here https://github.com/bumptech/glide/issues/4485#issuecomment-2249277941 fixed the problem.

awb-i4o avatar May 30 '25 14:05 awb-i4o