Calculation Formula for memory usage of Android Bitmap, androidbitmap

Source: Internet
Author: User

Calculation Formula for memory usage of Android Bitmap, androidbitmap

Android definition of each resolution

Calculation method when the image is stored in ARGB_8888 format

Memory usage = image length * Image Width * 4 bytes

Image length = original image Length (Device DPI/folder DPI) Image Width = Original Image Width(Device DPI/folder DPI)

 

The example is as follows:

The image size is 200*320. The device is a red-meter dpi of 320 and belongs to an xhdpi device.

Verify that an image is placed in hdpi and the output result is as follows:
DD/MainActivity (13014): dpi: 320 bitmap ByteCount: 456036

Image length = (320/240) * 200 = 266.67

Image Width = (320/240) * 320 = 426.67

Memory usage = 266.67*426.67*4 = 455116 is roughly the same as the actual value

 

Verification 2: The image is placed under xxhdpi and the code output is as follows:

D/MainActivity (13014): dpi: 320 bitmap ByteCount: 113316

Image length = (320/480) * 200 = 133.33

Image Width = (320/480) * 320 = 213.33

Memory usage = 133.33*213.33*4 = 113774 is roughly the same as the actual value.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.