Android Compute Bitmap Size

Source: Internet
Author: User

To get the size of bitmap today, use LRUCache to write the demo

So I used it.

return Bitmap.getrowbytes () * bitmap.getheight ();//Get size and return
The number of memory space occupied by bitmap is equal to the number of spaces occupied by each row of bitmap multiplied by the number of bitmap rows


Why not Bitmap.getbytecount ()?
Because GetByteCount requires a high version of the API, consider compatibility using the methods above


1. Getrowbytes:since API Level 1
2. Getbytecount:since API Level 12


View Bitmap Source code

[Java]View PlainCopyprint?
    1. Public Final int getByteCount () {
    2. return Getrowbytes () * getheight ();
    3. }


So after API 12
GetByteCount () = Getrowbytes () * getheight ();


The method above may be helpful when calculating the space occupied by bitmap.

Add:

[Java]View PlainCopyprint?
    1. /**
    2. * Get the size of bitmap
    3. */
    4. public static int getbitmapsize (Bitmap Bitmap) {
    5. if (Build.VERSION.SDK_INT >= build.version_codes. KITKAT) { //api
    6. return Bitmap.getallocationbytecount ();
    7. }
    8. if (Build.VERSION.SDK_INT >= build.version_codes. HONEYCOMB_MR1) {//api
    9. return Bitmap.getbytecount ();
    10. }
    11. //byte x height with one row in the lower version
    12. return Bitmap.getrowbytes () * Bitmap.getheight (); //earlier version
    13. }

Android Compute Bitmap Size

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.