出的Andr​​oid上的内存图像捕获图像、内存、Andr、oid

2023-09-05 10:59:15 作者:青风吹过的残言细语丶

我有一个活动这需要照片(全文可能的解决方案,使相当大),应用程序必须然后分析它们的机会。只有一张照片是在同一时间处理。问题是,我经过4运行一个内存不足 - 5张照片。我看

I have an Activity which takes photos (with full possible resolution, so quite large), the application have then the chance to analyze them. Only one photo is handled at a time. The problem is that I run in to a "Out of memory" after 4 - 5 photos. I see

dalvikvm堆内存不足。在5070745字节分配

dalvikvm-heap Out of memory on a 5070745-byte allocation

(字节大小而异),然后按

(the byte size varies) followed by

相机-JNI无法分配字节数组JPEG数据

Camera-JNI Couldn't allocate byte array for JPEG data

我的应用程序不会崩溃,但它出现在我的相机根本就无法从这个角度上提供的图像。我注重内存使用情况在我的应用程序,但这里似乎存在内存泄漏的地方之外,我在问我,我怎么能应付这个。任何解决办法存在的呢?

My application does not crash but as it appears to me the Camera simply becomes unable to deliver the images from this point on. I pay attention to memory usage in my application but here it seems that there is a memory leak somewhere outside and I'm asking me how can I cope with this. Any solution approaches existing for this?

推荐答案

这可能不是你想到底该怎么做,但为了在网格视图中显示多个大型画册(4-6 MB),我发现这code创建一个较小的位图质量较低,避免了内存不足的情况​​:

This may not be exactly what you are trying to do, but in order to display multiple large pictures (4-6 MB) on a grid view, I found this code to create a smaller bitmap with lower quality, to avoid out-of-memory situations:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 5;
options.inPurgeable = true;
options.inInputShareable = true;
Bitmap bm = BitmapFactory.decodeFile("/sdcard/myapp/" + filesFound.get(position), options);

该选项的重要组成部分,并通过改变设置,我设法采取记忆下来,从哪里会崩溃,约28MB,当我开始使用inSampleSize。它进一步下降的inPurgeable,并设置为true inInputShareable设置。我的活动仍然低迷,但它的好多了。

The options are the important part, and by varying the settings, I managed to take memory down from where it would crash, to around 28MB when I started using the inSampleSize. It further went down with the inPurgeable and inInputShareable settings set to true. My activity is still sluggish, but it's much better.

有关您的应用程序,如果它可以分析一个位图,上面的code可能萎缩下来的内存使用量足以令它的工作。我还是新来的Andr​​oid,所以有可能这可能不是在所有工作..; - 。)

For your application, if it can analyze a bitmap, the above code may shrink down the memory usage enough to make it work. I'm still new to Android, so it's possible this may not work at all.. ;-).

问候,

凯文

 
精彩推荐
图片推荐