Android 图库,可缩放大图像
我尝试实现一个图库,其中每个项目都是一个大图像,以实现良好的放大功能。 问题在于内存的管理。 当我尝试转到第四个元素时,android 会出现“内存不足”,因此我尝试回收未显示的图像,但 android 会转到 RunTimeException,以便在我回来时尝试使用回收的图像。 另外,我尝试更改未与小图像位图一起显示的大图像的位图,但总是出现内存不足。
我该如何管理图库的内存?
I try to implement a Gallery where each item is a big image for a good zomm-in function.
The problem is the management of the memory.
When i try to go to the fourth element android goes to Out Of Memory, so i try to recycle the images not displayed, but android goes to RunTimeException for try to use a recycled image when i come back.
Also i try to change the bitmap of the bigs images not displayed with bitmap of small images but always goes to Out Of Memory.
How can i do, for manage the memory of the Gallery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用 recycle() 后,确保您不再使用该位图引用,因为如果调用某些方法,这将导致运行时异常。尝试使用 SoftReference 包裹位图。这将保证在抛出 OutOfMemoryError 之前回收所有不再引用的内存。
After you do call recycle(), make sure you don't use that Bitmap reference again as that will cause a runtime exception if certain methods are invoked. Try using SoftReferences wrapped around your bitmaps. This will guarantee that all of the memory that is no longer references will be reclaimed before an OutOfMemoryError is thrown.