为什么这么多的内存? [英] Why so much memory?

查看:126
本文介绍了为什么这么多的内存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我想要一个可变的副本Android的一个1000x1500像素的位图。

I have a 1000x1500 pixel bitmap of which I want to make a mutable copy in Android.

当我运行下面的code ...

When I run the following code...

// int width = original.getWidth(); // 1000px
// int height = original.getHeight(); // 1500px
final Bitmap result = original.copy(original.getConfig(), true);
original.recycle();

...我得到一个的OutOfMemoryError 复制行:

java.lang.OutOfMemoryError: bitmap size exceeds VM budget
ERROR/GraphicsJNI(419): VM won't let us allocate 6000000 bytes

为什么会出现复制指令需要的 6MB (!)为1000x1500像素的位图?

Why does the copy instruction need 6MB (!) for a 1000x1500 pixel bitmap?

我怎样才能在内存更有效的方式创建一个不可变一个可变的位图?

How can I create a mutable bitmap from a non-mutable one in more memory-efficient way?

BitmapFactory 返回inmutable位图。显然,从一个不变的1创造了可变位的唯一方法是将其复制到一个新的可变位图。在1000x1500位图的情况下,这显然是需要的 12MB (1000x1500x4x2),这将导致在大多数Android设备OutOfMemoryError异常。

BitmapFactory returns inmutable bitmaps. Apparently, the only way of creating a mutable bitmap from an immutable one is to copy it into a new mutable bitmap. In the case of a 1000x1500 bitmap, this apparently requires 12MB (1000x1500x4x2), which causes an OutOfMemoryError in most Android devices.

这是无法解决的问题在Android的呢?

Is this problem unsolvable in Android then?

推荐答案

cdonner 把我在正确的方向。

原来,原来的位图使用的 ARGB_8888 ,这需要每像素32位,并超过需要什么,这个特殊的应用程序。

Turns out that the original bitmap was using ARGB_8888, which requires 32 bits per pixel and is more than what was needed for this particular app.

更改位图配置 RGB_565 ,这需要每像素16位,减少内存消耗了一半。

Changing the bitmap config to RGB_565, which requires 16 bits per pixel, reduced memory consumption by half.

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

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