1

I have to display some pictures in an ImageView. Some of them may have a resolution too high that gives me

W/OpenGLRenderer﹕ Bitmap too large to be uploaded into a texture (3744x5616, max=4096x4096)

I used this method to detect this situation:

public boolean isResTooHigh() {
    int[] maxSize = new int[1];
    GLES10.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxSize, 0);

    return (maxSize[0] < width) || (maxSize[0] < height);
}

where width and height are provided by the source of the pictures.

But now on my Nexus 4 running Lollipop and my emulators, maxSize[0] is always 0. So, how do I detect this problem?

FD_
  • 12,947
  • 4
  • 35
  • 62
andrew
  • 3,879
  • 4
  • 25
  • 43
  • did you check last opengl error after this call ? – Selvin Nov 19 '14 at 21:09
  • "W/OpenGLRenderer﹕ Bitmap too large to be uploaded into a texture (3744x5616, max=4096x4096)" is the only error I get. – andrew Nov 19 '14 at 21:15
  • after glGetIntegerv ... with http://developer.android.com/reference/javax/microedition/khronos/opengles/GL10.html#glGetError() – Selvin Nov 19 '14 at 21:17

2 Answers2

1

Technically you're only guaranteed to be able to render single bitmaps that are the size of the screen or smaller. You might be able to render bigger ones on some hardware, but it is unpredictable -- and as I said, the only actual guarantee is that you will be able to render something the size of the screen (or smaller).

To display bigger images, split up your UI into tiles, each of which is no bigger than the screen in either dimension.

ctate
  • 1,379
  • 10
  • 11
  • I know I can't display them. If the size of the picture is too high, I simply don't show it. But I need to know when the size is too high. – andrew Nov 19 '14 at 21:30
  • You can't know, really. Just always break your view up into 256x256 or 512x512 tiles and handle everything that way. Your users will thank you! – ctate Nov 19 '14 at 21:31
  • For a tiled view you'd probably want to use more like 256x256 or 512x512 tiles. There are libraries such as this: https://github.com/davemorrissey/subsampling-scale-image-view that will do this for you (specifically the SubsamplingScaleImageView). – John Reck Nov 19 '14 at 21:32
1

That GL query requires an active GL context on the thread. Previously your app was accidentally using framework's private GL context to perform that query. In Lollipop due to various architecture changes this context no longer leaks into application code, hence why the query is now failing. If you look in logcat you will probably see something like: "call to opengl es api with no current context".

You can create your own GL context to perform that query if you want. Alternatively you can assume the screen resolution is the maximum, or use a scalable solution such as a tiled approach.

John Reck
  • 341
  • 2
  • 4