Android gets the size of bitmap

Source: Internet
Author: User

Recently entered the new company internship, when looking at the project code to see the previous colleague is so written code to get the size of bitmap:

return Bitmap.getrowbytes () * bitmap.getheight ();//Get size and return

It feels strange why this is calculated instead of calling Bitmap.getbytecount directly ();

After reviewing the document, it is not known that the project is minsdk=8,targetsdk=19 and therefore cannot be called directly, but written in this way. However, I still feel that this is not rigorous, because the API level 12 after the version of the new method is still used.

Here's a summary of the code to get the bitmap image size:

public int getbitmapsize (Bitmap Bitmap) {if (Build.VERSION.SDK_INT >= build.version_codes. KITKAT) {//api 19return bitmap.getallocationbytecount ();} if (Build.VERSION.SDK_INT >= build.version_codes. HONEYCOMB_MR1) {//api 12return bitmap.getbytecount ();} return Bitmap.getrowbytes () * Bitmap.getheight ();//earlier version}


This article is from the "Flying Cat" blog, be sure to keep this source http://flyingcat2013.blog.51cto.com/7061638/1564228

Android gets the size of bitmap

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.