Why so much memory?

I have a 1000x1500 pixel bitmap from which I want to make a modified copy in Android.

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();

... I get OutOfMemoryErrorin the line copy:

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

Why do I need a 6 MB copy command (!) For a 1000x1500 bitmap?

How can I create a mutable bitmap from a non-moving one more efficiently in terms of memory?

Edit

BitmapFactory inmutable . -, - . 1000x1500 , -, 12 (1000x1500x4x2), OutOfMemoryError Android-.

Android?

+3
4

cdonner .

, ARGB_8888, 32 , .

config RGB_565, 16 , .

+5

:

1000 * 1500 * 32/8 = 6000000

(32 / )

: , , .

+5

, , OutOfMemoryError. , :

<receiver android:name=".ImageTransformReceiver"
             android:exported="true" android:process=":imageTransformProcess"/>

( ). , Intent.

This is just a hack that allows you to use more OS memory in one application. Hope this helps.

+4
source

By API level 11, BitmapFactory.Options has a logical value of 'inMutable', which can be set to create modified bitmaps.

Although this does not change the memory usage for a single bitmap, it saves you the trouble of storing two copies in memory.

+2
source

Source: https://habr.com/ru/post/1786178/


All Articles