question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Image size can exceeds the limit after resize, causing 'Bitmap too large to be uploaded into a texture'

See original GitHub issue

I’d like to display an image as large as possible within the limit, so I decided to write code as following:

ImageRequest req = ImageRequestBuilder.newBuilderWithSource(Uri.parse(NETWORK_IMAGE_URL))
        .setResizeOptions(new ResizeOptions(2048, 2048))
        .build();

SimpleDraweeView v = (SimpleDraweeView) holder.itemView;
v.setAspectRatio(IMAGE_ASPECT_RATIO);

DraweeController ctrl = Fresco.newDraweeControllerBuilder()
        .setOldController(v.getController())
        .setImageRequest(req)
        .setAutoPlayAnimations(true)
        .build();

v.setController(ctrl);

When I run above code with the image whose dimension is 720px*2478px, it is not displayed on the screen but getting following logcat message:

W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (630x2169, max=2048x2048)

So I checked the imagepipeline to see what is happening in the resize procedure, found something weird in generating the numerator.

The numerator is generated In the method getScaleNumerator(ImageRequest, EncodedImage) from ResizeAndRotateProducer class, which calls roundNumerator(float) to get numerator from the ratio generated from `determineResizeRatio(ResizeOptions, int, int).

While getting a numerator value from roundNumerator(float) method, it adds extra ROUNDUP_FRACTION to maxRatio * JpegTranscoder.SCALE_DENOMINATOR, causing the numerator be more than the expected in some cases.

I tracked the value from each process, and the result is as follows:

In getScaleNumerator():

  • determineResizeRatio() returned 0.82647294
  • roundNumerator() returned 7

In doTransform()

  • numerator is genrated from getScaleNumerator()
  • With the numerator 7, JpegTranscoder resizes the image into 7/8 of its original size, results resized one has a size of 630px*2169px.

While the final image’s height has larger than the limit (BitmapUtil.MAX_BITMAP_SIZE), it will not be shown on the screen.

When I remove adding the ROUNDUP_FRACTION in method roundNumerator(float), it generates a numerator of 6, which resizes the image smaller than the limit(2048px), results final image size of 540px * 1859px.

Here’s a question:

  • Why additional ROUNDUP_FRACTION is required in generating the numerator?
  • If adding ROUNDUP_FRACTION is intended and cannot be modified, how can I avoid the above error?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Bots22commented, Jun 4, 2016

Hey there , we’ve been asked to contribute on a github project as a semester task of our university (me and my teammate) and since we liked fresco a lot we decided to try to help out here! We found this issue interesting and we tried to make a progress on kunny’s work. I’m attaching our pull request that reffers on this issue! #1273

0reactions
michalgrcommented, Jan 14, 2016

Marking as a starter-task in case anyone wants to help to get this done sooner than later.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Prevent bitmap too large to be uploaded into a texture android
Basically, the maximum image dimensions are a system-imposed limit. The above approach will correctly resize bitmaps that exceed this limit. However, only a ......
Read more >
Android – Load big size image issue in imageview . Bitmap ...
I have 270 x 2693 pixel image in drawable folder . When i try to set that image in imagview i got Bitmap...
Read more >
Loading Large Bitmaps Efficiently - Android Developers
Images come in all shapes and sizes. In many cases they are larger than required for a typical application user interface (UI).
Read more >
Common Mistakes - OpenGL Wiki - Khronos Group
This problem usually manifests itself with constructors, when a user creates a texture object or similar OpenGL object wrapper at global scope.
Read more >
The Simple Guide to WordPress Image Sizes - Visual Composer
Thumbnail size (150px square); Medium size (maximum 300px width and height); Large size (maximum 1024px width and height); Full size (full/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found