Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add support for max_width/max_height in ImageView size resolution. #1514

Open
benoitletondor opened this issue Oct 20, 2022 · 2 comments
Open
Labels
enhancement New feature or request help wanted Issues that are up for grabs + are good candidates for community PRs

Comments

@benoitletondor
Copy link

benoitletondor commented Oct 20, 2022

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 a maxHeight of 300dp, so I would expect the Dimension for height to be at max 300dp and not Undefined
  • 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

@colinrtwhite colinrtwhite added help wanted Issues that are up for grabs + are good candidates for community PRs enhancement New feature or request labels Oct 20, 2022
@colinrtwhite
Copy link
Member

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.

@colinrtwhite
Copy link
Member

Coil 1.4.0 constrained the max output image size in this case to the size of the display, which had some other issues.

@colinrtwhite colinrtwhite changed the title RuntimeException thrown when loading a big image into a wrap_content ImageView with maxHeight set Add support for max_width/max_height in imageview size resolution. Oct 20, 2022
@colinrtwhite colinrtwhite changed the title Add support for max_width/max_height in imageview size resolution. Add support for max_width/max_height in ImageView size resolution. Oct 20, 2022
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request help wanted Issues that are up for grabs + are good candidates for community PRs
Projects
None yet
Development

No branches or pull requests

2 participants