位图的大小超过VM预算的android位图、预算、大小、VM

由网友(拽是姐的专利)分享简介:闻听此事05-25 23:55:59.145: ERROR/AndroidRuntime(3257): java.lang.OutOfMemoryError: bitmap size exceeds VM budget在我的这个code - at this code of mine - Bitmap cs =...

闻听此事

05-25 23:55:59.145: ERROR/AndroidRuntime(3257): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

在我的这个code -

at this code of mine -

Bitmap cs = null;

    cs = Bitmap.createBitmap(frameImg.getWidth(), frameImg.getHeight(), Bitmap.Config.ARGB_8888);

在活动课。如何解决这个问题:(

in activity class. How to fix this :(

推荐答案

我从我的EVO选择图像时遇到了类似的问题...关闭SD卡。相机保存这些图像在超过1M一块,并在某些情况下接近300 MB。讽刺的是,位图的意图的大小发送给你的时候拍照只有大约40 KB。

I ran into a similar problem when selecting images from my EVO ... off the SD Card. The camera saves those images at over 1MB a piece, and in some cases close to 3 MB. Ironically, the size of the bitmap the Intent sends to you when "taking a picture" is only about 40 Kb.

我想出了解决的办法是:

The solution I came up with was:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;    // this will cut the sampling by 50%
Bitmap bitmap = BitmapFactory.decodeFile( imageFilePath, options );

我能拍照和削减他们下到不到100 KB通过增加因素数量,图像依然pretty的优良品质。

I was able to take pictures and cut them down to less than 100 Kb by increasing the factor number, and the images were still pretty good quality.

底线这里是prevented OOME错误,因此$ P $由超过堆分配破碎的JVM pvent我。简单 - 有效

The bottom line here is it prevented OOME errors, and thus prevent me from crushing the JVM by exceeding the heap allocation. Simple - effective.

您可能会发现这是一个有趣的阅读也:BitmapFactory OOM我发疯

You might find this an interesting read also: BitmapFactory OOM driving me nuts

阅读全文

相关推荐

最新文章