Where the heck is Bitmap getByteCount()?

后端 未结 7 2006
时光取名叫无心
时光取名叫无心 2021-01-02 05:46

I know the Android platform is a huge mess, over complicated and over-engineered, but seriously to get the size of a bitmap, is it really necessary to do all those conversio

相关标签:
7条回答
  • 2021-01-02 06:12

    The answers here are a bit outdated. Reason (in the docs) :

    getByteCount : As of KITKAT, the result of this method can no longer be used to determine memory usage of a bitmap. See getAllocationByteCount().

    So, the current answer should be :

    int result=BitmapCompat.getAllocationByteCount(bitmap)

    or, if you insist on writing it yourself:

    public static int getBitmapByteCount(Bitmap bitmap) {
        if (VERSION.SDK_INT < VERSION_CODES.HONEYCOMB_MR1)
            return bitmap.getRowBytes() * bitmap.getHeight();
        if (VERSION.SDK_INT < VERSION_CODES.KITKAT)
            return bitmap.getByteCount();
        return bitmap.getAllocationByteCount();
    }
    
    0 讨论(0)
提交回复
热议问题