Search code examples
androidimage-processingandroid-imageviewandroid-imageandroid-5.0-lollipop

Detect if resolution is too high on Android Lollipop


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?


Solution

  • 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.