本文讨论了Android中硬件加速器hardwareAccelerated可能导致的大图加载问题,包括Bitmap too large to be uploaded into a texture的错误。通过关闭硬件加速或者使用BitmapRegionDecoder分块加载图片来解决此问题。此外,还提到了内存溢出问题的解决策略,如减小图片尺寸、及时释放Bitmap对象和调整程序heap size。
<!-- hardwareAccelerated是硬件加速,在这儿将其关掉是为了加载大的背景图,如果硬件加速是true 那么会对大的位图限制有限制,不允许大图显示,此时报出Bitmap too large to be uploaded into a texture (2880x5120, max=4096x4096) 的错误,这里简单粗暴的将hardwareAccelerated设置为false。更好的办法可以将图片分成不同的块,每次加载需要的块。 android提供了一个这样的方法http://developer.android.com/reference/android/graphics/BitmapRegionDecoder.html 可以研究下谷歌的这个方法。 -->
Whether your application's processes should be created with a large Dalvik heap. This applies to all processes created for the application. It only applies to the first application loaded into a process; if you're using a shared user ID to allow multiple applications to use a process, they all must use thisoption consistently or they will have unpredictable results.
2
Most apps should not need thisand should instead focus on reducing their overall memory usage forimproved performance. Enabling thisalso does not guarantee a fixed increase in available memory, because some devices are constrained by their total available memory.
3
To query the available memory size at runtime, use the methods getMemoryClass() or getLargeMemoryClass().
Whether or not hardware-accelerated rendering should be enabled forall activities and views in thisapplication — "true"ifit should be enabled, and "false"ifnot. The defaultvalue is "true" ifyou've set either minSdkVersion or targetSdkVersion to "14" or higher; otherwise, it's "false".
5
Starting from Android 3.0(API level 11), a hardware-accelerated OpenGL renderer is available to applications, to improve performance formany common 2D graphics operations. When the hardware-accelerated renderer is enabled, most operations in Canvas, Paint, Xfermode, ColorFilter, Shader, and Camera are accelerated. This results in smoother animations, smoother scrolling, and improved responsiveness overall, even forapplications that donot explicitly make use the framework's OpenGL libraries.
6
Note that not all of the OpenGL 2D operations are accelerated. If you enable the hardware-accelerated renderer, test your application to ensure that it can make use of the renderer without errors.
7
For more information, read the Hardware Acceleration guide.