Loading bitmap with too large height in android ImageView

510 Views Asked by At

I am stuck with a weird issue with bitmap, I have some images saved locally in my app with too large height and i am showing the images in a imageview which support zoom and pan. what i am doing is i am getting the bitmap of the image using universal image loader and then loading that bitmap in a imageview. Now if i am showing the bitmap as it is without scaling the image using :

DisplayImageOptions opts = new 
DisplayImageOptions.Builder().imageScaleType(ImageScaleType.NONE).build();
bitmap = ImageLoader.getInstance().loadImageSync(uri.toString(), opts);

then nothing is showing in a imageview but i am getting the error in logcat :

W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (686x7628, max=4096x4096)

and if i am trying to load the image with scaling then quality of image gets destroyed as image contain text only it is not readable.

ScreenShot from device :

enter image description here

Original Image :

enter image description here

Size of Image is 1.2Mb only i don't know how to handle this as all the libraries i tried reducing the quality of image to non readable formate and if i am trying to load image bitmap directly to imageview it is not showing. Any help is Appreciated.

2

There are 2 best solutions below

0
Manoj Perumarath On

You can get the maximum supported dimension for a device using

 val canvas = Canvas()
    canvas.getMaximumBitmapHeight()
    canvas.getMaximumBitmapWidth()

As per the doc

For height

/**
 * Returns the maximum allowed height for bitmaps drawn with this canvas.
 * Attempting to draw with a bitmap taller than this value will result
 * in an error.
 *
 * @see #getMaximumBitmapWidth()
 */
public int getMaximumBitmapHeight() {
    return MAXMIMUM_BITMAP_SIZE;
}

For width

 /**
 * Returns the maximum allowed width for bitmaps drawn with this canvas.
 * Attempting to draw with a bitmap wider than this value will result
 * in an error.
 *
 * @see #getMaximumBitmapHeight()
 */
public int getMaximumBitmapWidth() {
    return MAXMIMUM_BITMAP_SIZE;
}

So while setting the Bitmap you should consider these dimensions and set the Bitmap accordingly.

1
nostra13 On

Well, I think image-loading libraries won't help you with such images. Library should scale original image for size less max texture size. So those long images are vastly scaled resulting non-readable text. In your case you should handle image loading yourself: fetch image and draw it on canvas, maybe by parts or somehow.

Anyway, loading text as image of those size looks like not very great idea :)