问题
When I call Canvas.drawBitmap()
for a Bitmap
with more than 4096px on one side - I get nothing. No errors and no bitmap drawn. There appears only this message in LogCat:
W/OpenGLRenderer: Bitmap too large to be uploaded into a texture (2880x4920, max=4096x4096)
This leads to these questions:
- What does the limit of 4096x4096 depend on? The Android version? The Kernel drivers? Or the Hardware?
- How can I check this limit at runtime for the current device?
- How can I catch the error "W/OpenGLRenderer: Bitmap too large ..."?
回答1:
It depends on both hardware and software. You can query at runtime with a valid OpenGL context (see: Get OpenGL max texture size)
int[] maxTextureSize = new int[1];
GLES10.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);
Note that the supported size might be smaller, depending on the format of the texture. For example, your hardware could also have a maximum texture size, in bytes, in addition to a maximum size in pixels. To check what texture size is supported, create a proxy texture (GL_PROXY_TEXTURE_2D
target, instead of GL_TEXTURE_2D
) with the size and format you want, and then query the texture size (width or height) with glGetTexLevelParameteriv()
. If your texture is too big, the size will be set to 0.
来源:https://stackoverflow.com/questions/34976645/android-w-openglrenderer-bitmap-too-large-to-be-uploaded-into-a-texture