安卓:" java的郎的OutOfMemoryError位图,大小超过-VM-预算的android"虽然从SD卡中装载位图? [英] Android: "java-lang-outofmemoryerror-bitmap-size-exceeds-vm-budget-android" While loading bitmaps from sdcard?

查看:134
本文介绍了安卓:" java的郎的OutOfMemoryError位图,大小超过-VM-预算的android"虽然从SD卡中装载位图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序要显示的图像大约是10000×5000,采用500×500的像素的小图像。即;直通平铺图像。 为了平铺所有图像一开始我收集从SD卡所有的位图,以吸引在画布上。

不过,虽然使用 BitmapFactory.de codeFILE(路径)我encounterd错误时加载图像从extenal存储的java琅的OutOfMemoryError,bitmap-大小超过-VM-预算的android

任何一个可以如何避免这个错误,并给我一个想法瓷砖如何大量的图像在一个单一的形象。

感谢你, SRINIVAS

解决方案
  1. 从不加载,你不需要任何的瓷砖。 我收集从SD卡的所有位图,这表明你是DECOM pressing每一个形象,你可能永远都需要,这将是错误的做法。

  2. 使用更小的砖。 256×256是一个很好的大小。

  3. 加载它们作为Config.RGB565(即16bpp的)。

  4. 定期回收()位图,你不需要。

基本上你需要实现某种最最近使用(MRU)位图缓存。

In my application I have to display an image which is about 10000 x 5000 , using small images of 500x500 px. I.e;thru tiling images. In order to tile all images to one initially am collecting all bitmaps from sdcard in order to draw on canvas.

But while am loading images from extenal storage using BitmapFactory.decodeFile(path) i encounterd with error java-lang-outofmemoryerror-bitmap-size-exceeds-vm-budget-android

can any one how to avoid this error and gimme an idea how to tile lot of images in to a single image .

Thanking you, Srinivas

解决方案

  1. Never load any tiles that you don't need. "am collecting all bitmaps from sdcard" suggests that you are decompressing every image you might ever need, which would be the wrong approach.

  2. Use smaller tiles. 256x256 is a good size.

  3. Load them as Config.RGB565 (i.e. 16bpp).

  4. Regularly recycle() Bitmaps you don't need.

Basically you need to implement some sort of most-recently-used (MRU) Bitmap cache.

这篇关于安卓:" java的郎的OutOfMemoryError位图,大小超过-VM-预算的android"虽然从SD卡中装载位图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆