Android Bitmap Memory Usage Calculation formula

Source: Internet
Author: User

Android's definition of each resolution

How to calculate when a picture is stored in a format argb_8888

Memory consumption = picture length * Picture width/bytes

Picture length = picture original long (Device dpi/folder dpi) Picture width = Picture original width (device dpi/folder dpi)

Examples of validation are as follows:

Picture size 200 * 320, device is red meter dpi is 320, belongs to xhdpi device.

Verify that a picture is placed in hdpi and the following is the result of the code output:
Dd/mainactivity (13014): dpi:320 bitmap bytecount:456036

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

Picture width = (320/240) * 320 = 426.67

Memory consumption = 266.67 * 426.67 * 4 = 455116 approximately the same as the actual value

Verification two: Picture put xxhdpi, below for code output result:

D/mainactivity (13014): dpi:320    bitmap bytecount:113316

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

Picture width = (320/480) * 320 = 213.33

Memory consumption = 133.33 * 213.33 * 4 = 113774 is approximately the same as the actual value.

Android Bitmap Memory Usage Calculation formula

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.