Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Canvas: trying to draw too large bitmap. #648

Closed
beigirad opened this issue May 4, 2020 · 11 comments
Closed

Canvas: trying to draw too large bitmap. #648

beigirad opened this issue May 4, 2020 · 11 comments

Comments

@beigirad
Copy link
Contributor

beigirad commented May 4, 2020

Do you want to request a feature or report a bug?
bug

What is the current behavior?
When I pass a high-res image (10MB) to UCropFragment it crashed.
try this image

What is the expected behavior?
I expect it starts editing the image.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
Just choose a high-res image and see the crash.

Please attach any image files, URL and stack trace that can be used to reproduce the bug.

    Process: xxxxx, PID: 9937
    java.lang.RuntimeException: Canvas: trying to draw too large(290841740bytes) bitmap.
        at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:229)
        at android.view.RecordingCanvas.drawBitmap(RecordingCanvas.java:97)
        at com.yalantis.ucrop.util.FastBitmapDrawable.draw(FastBitmapDrawable.java:41)

Which versions of uCrop, and which Android API versions are affected by this issue? Did this work in previous versions of uCrop?
2.2.4

@beigirad
Copy link
Contributor Author

beigirad commented May 4, 2020

I checked the source of this crash:
in DisplayListCanvas has defined:

    private static final int MAX_BITMAP_SIZE = 100 * 1024 * 1024; // 100 MB

and then in this line

int bitmapSize = bitmap.getByteCount();
if (bitmapSize > MAX_BITMAP_SIZE) {
     throw new RuntimeException(
         "Canvas: trying to draw too large(" + bitmapSize + "bytes) bitmap.");
 }

I think this happens because we try to draw a high-quality bitmap for a preview in edit/cropping mode. and then retrieve this bitmap from view to process. instead, I think we can separate the preview bitmap from preprocessing bitmap.

It means the user interacts with a preview image and then he/she submits we start processing a high-quality bitmap. The difference is we don't need to show a high-quality bitmap.

@Jeff11
Copy link

Jeff11 commented May 11, 2020

Is it possible to have a hot fix version for this?

Since more and more people have get those high megapixel camera phones, this is now our number one crash reason.

@yushaojian13
Copy link

yushaojian13 commented Jun 2, 2020

I suggest a more proper solution, it won't crash and will continue to crop.

int bitmapSize = decodeSampledBitmap != null ? decodeSampledBitmap.getByteCount() : 0;
if (bitmapSize > MAX_BITMAP_SIZE) {
    options.inSampleSize *= 2;
    continue;
}

@cuiti
Copy link

cuiti commented Aug 3, 2020

Seems like this crash is getting more impactful as time goes by. Any news about a next release?

@dpreussler
Copy link

dpreussler commented Aug 10, 2020

hotifx would really be appreciated before everyone forks this library

@KDederichs
Copy link

any news on this? It's a rather annoying issue....

@asifbd
Copy link

asifbd commented Aug 27, 2020

I think a pull request with the fix has been merged and available in latest version (2.2.6)

@shreemaan-abhishek
Copy link

I suggest a more proper solution, it won't crash and will continue to crop.

int bitmapSize = decodeSampledBitmap != null ? decodeSampledBitmap.getByteCount() : 0;
if (bitmapSize > MAX_BITMAP_SIZE) {
    options.inSampleSize *= 2;
    continue;
}

Where should this code be placed??

@beigirad
Copy link
Contributor Author

beigirad commented Sep 3, 2020

This issue has fixed in version 2.2.6

@sauniksingh
Copy link

java.lang.RuntimeException: Canvas: trying to draw too large(290841740bytes) bitmap. at android.graphics.BaseCanvas.nDrawBitmap(Native method) at android.graphics.BaseCanvas.drawBitmap(BaseCanvas.java:192) at android.graphics.Canvas.drawBitmap(Canvas.java:1660) at com.yalantis.ucrop.util.FastBitmapDrawable.draw(FastBitmapDrawable.java:41) at android.widget.ImageView.onDraw(ImageView.java:1444)

Still getting same issue if we're trying to crop image more than 4mb. in NOKIA 6.1, Android 10, & UCROP version 2.2.6

@heihitesh
Copy link

heihitesh commented Aug 28, 2024

I am getting the same error,
Also when I get to the UCrop screen to crop the image, If I press the back button. then also I get the same error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants