本文介绍了在imageview中加载大尺寸图像问题.位图太大,无法上传到纹理中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在drawable文件夹中有270 x 2693像素的图像.当我尝试在imagview中设置该图像时,我得到的位图太大,无法上传到纹理中警告.

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.

图像在android设备中完美设置<4.0,但未设置> 4.0设备.

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

请帮助我解决此问题.

代码

<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" />

这里的印地文是可绘制文件夹中的图像,尺寸为270 x 2693像素.

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

推荐答案

问题

此问题通常与OpenGL最大纹理大小或设备内存有关.您收到的完整错误可能类似于

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

大尺寸图像通常是内存问题,但在您的情况下270x2693是727110像素.如果使用RGBA,则每个像素为4字节,因此727110 * 4 = 2908440字节,大约为2.7兆字节.那应该适合任何设备.

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.

因此,您的问题可能与OpenGL有关.可能发生的情况是,您正在测试的Android设备> 4.0会检测到图像对于OpenGL而言过大,并为您调整大小,而较旧的设备则不会.

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.

就我而言,问题是我的640x1136初始图像似乎自动缩放为1280x2272图像大小,以适应设备的大屏幕.这也会触发您收到的错误消息.

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.

如果进一步发现此错误,则该错误与用于加载图像的dpi有关.正如您在Android参考上所发现的那样,设备将加载有关其dpi的图像,这可能会更改加载到内存中的图像的大小.

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.

  • 除了检测设备大小以进行选择外,您别无选择正确加载图像.

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

查看如何在内存中加载大位图.

您还可以为不同的设备dpi使用不同的图像尺寸可以通过Android从Drawable文件夹中自动选择.

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

请参见如何支持屏幕,其中介绍了如何设置你的文件夹.

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

如前所述,请使用较小的图像或减小其尺寸.

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

如果您需要支持多个屏幕,<.

Android还会收集数据,这些数据每7天更新一次,屏幕尺寸在他们的用户中.

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.

最后,如果您已经在应用程序中使用了OpenGL,请查看此答案,其中显示了如何检测最大的OpenGL纹理大小.

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.

这篇关于在imageview中加载大尺寸图像问题.位图太大,无法上传到纹理中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 13:28