coil
coil copied to clipboard
Add support for max_width/max_height in ImageView size resolution.
Related to #1349
Describe the bug
When loading a large image (from network or local) into an ImageView
that is set with wrap_content
for both width & height, the ViewSizeResolver
returns Dimension.Undefined
for both resulting on loading the image at full size and crashing the app with a java.lang.RuntimeException: Canvas: trying to draw too large(233280000bytes) bitmap.
error message.
That could be the normal behaviour but there are a few things to take in account:
- The
ImageView
has amaxHeight
of300dp
, so I would expect theDimension
for height to be at max300dp
and notUndefined
- It wasn't crashing with Coil version 1.4.0
To Reproduce
Just launch this app and it'll crash: coilsample.zip
Logs/Screenshots
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.coilsample, PID: 4365
java.lang.RuntimeException: Canvas: trying to draw too large(233280000bytes) bitmap.
at android.graphics.RecordingCanvas.throwIfCannotDraw(RecordingCanvas.java:266)
at android.graphics.BaseRecordingCanvas.drawBitmap(BaseRecordingCanvas.java:94)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:549)
at android.widget.ImageView.onDraw(ImageView.java:1446)
at android.view.View.draw(View.java:23195)
at android.view.View.updateDisplayListIfDirty(View.java:22062)
at android.view.View.draw(View.java:22926)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at androidx.constraintlayout.widget.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1994)
at android.view.View.updateDisplayListIfDirty(View.java:22053)
at android.view.View.draw(View.java:22926)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.updateDisplayListIfDirty(View.java:22053)
at android.view.View.draw(View.java:22926)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.updateDisplayListIfDirty(View.java:22053)
at android.view.View.draw(View.java:22926)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.updateDisplayListIfDirty(View.java:22053)
at android.view.View.draw(View.java:22926)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.updateDisplayListIfDirty(View.java:22053)
at android.view.View.draw(View.java:22926)
at android.view.ViewGroup.drawChild(ViewGroup.java:4529)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4290)
at android.view.View.draw(View.java:23198)
at com.android.internal.policy.DecorView.draw(DecorView.java:819)
at android.view.View.updateDisplayListIfDirty(View.java:22062)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:682)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:688)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:786)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:4579)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:4290)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:3517)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:2286)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:8948)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1231)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1239)
at android.view.Choreographer.doCallbacks(Choreographer.java:899)
at android.view.Choreographer.doFrame(Choreographer.java:832)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1214)
at android.os.Handler.handleCallback(Handler.java:942)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7898)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Version 2.2.2, no matter the Android API version
Yep, this is currently intended behaviour as Coil doesn't take maxHeight
into account (neither do other image loaders). We could potentially add support for this, but it's a behaviour change so we'd have to be careful about it.
Coil 1.4.0 constrained the max output image size in this case to the size of the display, which had some other issues.