1

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.

Kapil Rajput
  • 11,429
  • 9
  • 50
  • 65
  • This is quite large image in pixels . Try to load it `HttpUrlConnection` once and MOdify the `ImageView` . [See this](https://stackoverflow.com/questions/39273390/android-how-to-place-a-scrollable-photo-into-imageview) . There are also some libraries available to load high resolution Bitmaps .You can also use `WebView` to load this image. – ADM Apr 04 '19 at 07:37
  • Benefit with `WebView` is it will cache it automatically .And it provide auto Scroll . – ADM Apr 04 '19 at 07:44
  • @ADM i am using `imageview ` which supports Zoom and Pan, using `webview` will have bad user experience i think – Kapil Rajput Apr 04 '19 at 07:51

2 Answers2

0

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.

Manoj Perumarath
  • 9,337
  • 8
  • 56
  • 77
0

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 :)

nostra13
  • 12,377
  • 3
  • 33
  • 43
  • Thanks for your reply. can you please share some idea or any helpful link how to fetch image and draw it on canvas. I tried but found no success till today. – Kapil Rajput Apr 10 '19 at 12:57