Load big size image issue in imageview . Bitmap too large to be uploaded into a texture

非 Y 不嫁゛ 提交于 2019-12-08 20:38:26

问题


I have 270 x 2693 pixel image in drawable folder . When i try to set that image in imagview i got Bitmap too large to be uploaded into a texture warning.

Image sets perfectly in android device < 4.0 but not sets > 4.0 device.

Please help me to resolve this issue.

Code

<ImageView
   android:id="@+id/imageView"
   android:layout_width="fill_parent"
   android:layout_height="wrap_content"
   android:scaleType="fitXY"
   android:contentDescription="@string/name"
   android:src="@drawable/hindi" />

Here hindi is a image in drawable folder and its size is 270 x 2693 pixel.


回答1:


Problem

This problem is usually related either to OpenGL maximum texture size or the Device Memory. The full error you are getting is probably something like

W/OpenGLRenderer(12681): Bitmap too large to be uploaded into a texture (270x2693, max=2048x2048)

Memory is generally the problem with a large scale image but in your case 270x2693 is 727110 pixels. If you are in RGBA, it's 4 bytes per pixel so 727110 * 4 = 2908440 bytes, which is approximately 2,7 megabytes. That should fit on any devices.

Thus, your problem is probably related to OpenGL. What might happen is that the Android device > 4.0 you are testing on detect that your image is too large for OpenGL and resize it for you, while older devices don't.

Edit:

In my case, the problem is that my 640x1136 splash image seems to get rezised automatically to a 1280x2272 image size to fit my device huge screen. Which also triggers the error message you are having.

If you get this error further on, it is related to the dpi that is used to load the image. As you will find on Android reference, device will load image regarding their dpi which can alter the size of image that is loaded in memory.

Solution

  • You don't have much choice other than detecting the device size to load the image properly.

    See how to load large bitmap in memory.

  • You can also use different image size for different device dpi which can be automatically selected from the Drawable folder by Android.

    See the How to support screens which tells you how to setup your folder.

  • As other stated, use a smaller image or reduce its size.

Related informations

I suggest you have a look there if you need to support multiples screens.

Android also collect data which are updated every 7 days on Screens size among their users.

Also have a look to this interesting answer which points out a good website to understand Image Size in memory.

Finally, if you are already using OpenGL in your app, have a look to this answer which shows how to detect the max OpenGL texture size.




回答2:


Why not reduce the size of the image? If you don't want to do that, then rather than specify the bitmap in the XML, load it from program code, and scale it to fit the display. See this guide for more information on loading large bitmaps.




回答3:


try use this code

int[] maxTextureSize = new int[1];
GLES10.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxTextureSize, 0);

maxTextureSize stores the size limit for decoded image such as 4096x4096, 8192x8192 . Remember to run this piece of code in the MainThread or you will get Zero.



来源:https://stackoverflow.com/questions/15154031/load-big-size-image-issue-in-imageview-bitmap-too-large-to-be-uploaded-into-a

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!