android - 创建位图时内存不足异常 [英] android - out of memory exception when creating bitmap
问题描述
第二次创建位图后出现以下错误:
I am getting the following error after creating bitmap second time around:
04-17 18:28:09.310: ERROR/AndroidRuntime(3458): java.lang.OutOfMemoryError: bitmap size exceeds VM budget
this._profileBitmap = Bitmap.createBitmap(_profileBitmap, xCoor, yCoor, width, height);
来自日志:
04-17 18:27:57.500: INFO/CameraCropView(3458): Original Photo Size: W 1536 x H 2048
04-17 18:28:06.170: INFO/CameraCropView(3458): xCoor: 291
04-17 18:28:06.170: INFO/CameraCropView(3458): yCoor: 430
04-17 18:28:06.170: INFO/CameraCropView(3458): Width: 952
04-17 18:28:06.170: INFO/CameraCropView(3458): Height: 952
由于图像很大,我得到了错误.但有趣的是第一次不会发生错误,只有在我第二次拍照时才会发生,这让我相信这个 profileBitmap 没有被破坏.我该如何清理?
Since the image is huge I get the error. But the interesting thing is the error does not happen the first time, only when I take the picture the second time, which makes me believe this profileBitmap is NOT destroyed. How do I clean this up?
推荐答案
我遇到了同样的问题并通过以下方式解决:
I had the same problem and fix it this way:
我的应用程序大小约为 18MB,当我看到还有多少可用内存时,我感到震惊 - 654KB(在 1GB RAM 上!).所以我只是从项目中删除了几乎所有的图片,并在第一次启动时从互联网上下载它们,并在需要时使用 SD 卡中的图片.
My app was ~18MB size, and when I see how much memory left free I was shocked - 654KB (on 1GB RAM!). So I just deleted almost all images from project and downloaded them from the internet on first start, and use pics from SD card when needed.
要检查您的应用使用的总内存/可用内存:
To check total/free memory for your app use:
Runtime.getRuntime().totalMemory();
Runtime.getRuntime().freeMemory();
我忘记了主要内容 - 在您的清单中添加应用程序标签之间的这一行:
I forgot the main thing - add in your manifest, between application tag, this line:
android:largeHeap="true"
这篇关于android - 创建位图时内存不足异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!