Search code examples
androidcameratitaniumappcelerator-mobile

OpenGLRenderer: Bitmap too large to be uploaded into a texture in android titanium


In Titanium appcelerator, when I capture an image and show in an ImageView, image is not being shown, instead, below warning is being shown.

[WARN] : OpenGLRenderer: Bitmap too large to be uploaded into a texture (1840x3264, max=2048x2048)

How to solve this problem? Whereas in tablet it is working fine, but in high resolution device its not working.

This one occurs when I insert an image into a ImageView when shot from camera or pick from the gallery.


Solution

  • This is because different phones have different amounts of texture memory available depending on hardware, and their OpenGL version, this specific value is GL_MAX_TEXTURE_SIZE and can be looked up per phone here and in other places.

    To work around this, convert the image to a blob and then resize it using a built-in function: imageAsResized, in the success callback after taking a picture.

    Ti.Media.showCamera({
        ....
        success : function(e) {
            // Resized to a size that most phones should support
            var resizedImage = e.media.imageAsResized(1024, 1024);
            // Set the image view with the resized image
            imageView.image = resizedImage;
        },
        ....
    });