Will it save a lot of memory using 9-patch images?

I am struggling with OutOfMemoryError in my application.

I created a background image of 800 pixels x 480 pixels. When this image is loaded into a view that uses it as a background, I think the OS will use 800 * 480 * 4 bytes for it. This is a lot of memory.

If I create a 10-pixel image of 10 pixels with 9 patches to replace the entire image on the screen. The OS automatically scales the image with 9 patches to 800x480 when it displays a view using the 9 patch. My question is, in the case of 9 patches, how much memory will the OS use to draw a scaled 9 patch? will it be 10 * 10 * 4 bytes or 800 * 480 * 4 bytes?

Thanks.

+7
source share
1 answer

Firstly, if it is a background image and can be scaled, do it, since it is known that it is best practice (especially for the background), and a slight loss of image clarity can be compensated by choosing the right colors and / or background image.

As for memory, if you use Drawable, you are safe. But bitmaps, apparently, are not allocated in the standard way of Java, but through their own calls; distributions are performed outside the virtual heap, but are counted against it. Read more about this issue here.

+1
source

All Articles