位图图像的内存不足 [英] Bitmap Image out of memory

查看:182
本文介绍了位图图像的内存不足的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于Android的位图图像讨论出来的内存,但我想知道,如果有人可以解释给我..

I know there is a lot of discussion about android bitmap images out of memory but I was wondering if someone could explain it to me..

目前在我的应用程序,我有一个活动,列出图像的缩略图(低质量),当我点击图像它会打开一个新的活动,以查看图像全屏显示。在我的第二个活动课,我有:

Currently in my app I have an activity which lists image thumbnail (low quality) and when I click an image it opens a new activity to view the image full screen. In my 2nd activity class I have:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 1;
bm = BitmapFactory.decodeFile(myImagePath, options);

然后我把这个变成一个ImageView的显示它。这工作,并显示我的形象充分发挥其质量。但是,如果我点击回来,然后单击再次看到的图像(重复此6次).. 6日一次打开图像(活性2)我得到一个内存不足的错误说法堆大小= 6919KB,分配= 3125KB,位图大小= 25848KB!

I then put this into an ImageView to display it. This works and displays my image to its full quality. However if i click back and then click to see that image again (and repeat this 6 times) .. on the 6th time opening the image (activity2) I get an out of memory error saying Heap size=6919KB, Allocated=3125KB, Bitmap Size = 25848KB!

如何为位图尺寸那么大?我认为它可能会创建新实例所有的时间,所以我就决定把一个方法,我的第二个活动时,返回键为pressed..and在此方法中我把我的位图= null,并且也做了系统的研究。 GC()来清除垃圾收集但这并没有解决问题。我仍然得到了内存不足的错误上,单击缩略图的第6次来查看图像的完整

How is bitmap size that big? I assumed it may be creating new instances all the time so I then decided to put a method in my 2nd activity for when the back key is pressed..and in this method I set my bitmap=null and also did System.gc() to clear the garbage collector BUT this did not fix the problem. I still get an out of memory error on the 6th time of clicking on the thumbnail to view the image in full resolution

任何人都可以解释为什么?谢谢

Can anyone explain why? Thanks

推荐答案

有一个从机器人解释这一切在详细一些伟大的信息,以及如何克服这个问题的这里

There is some great information from android that explains it all in detail, and how to overcome this problem here.

每个像素是4字节。 6M像素= 24MBs

Each pixel is 4 Bytes. 6M Pixel = 24MBs

一张照片最多可使用所有的记忆。

One photo can use up all the Memory.

位图占用了大量的内存,尤其是丰富的图像,例如照片。例如,在Galaxy Nexus的相机拍摄的照片高达2592x1936像素(5百万像素)。如果使用位图配置ARGB_8888(从Android 2.3以后默认值),然后加载该图像到内存大约需要的内存(2592 * 1936年* 4字节)19MB,立即耗尽每个程序限制某些设备上。

Bitmaps take up a lot of memory, especially for rich images like photographs. For example, the camera on the Galaxy Nexus takes photos up to 2592x1936 pixels (5 megapixels). If the bitmap configuration used is ARGB_8888 (the default from the Android 2.3 onward) then loading this image into memory takes about 19MB of memory (2592*1936*4 bytes), immediately exhausting the per-app limit on some devices.

我再点你这个伟大的链接我发现从另一个SO问题,有教程如何正确过来的问题。

Again I point you to this great link I found from another SO Question that has tutorials of how to properly over come the problem.

这篇关于位图图像的内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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