Where the heck is Bitmap getByteCount()?

后端 未结 7 2033
时光取名叫无心
时光取名叫无心 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 05:51

    As mentioned in other answers, it is only available on API 12 or higher. This is a simple compatibility version of the method.

    public static int getByteCount(Bitmap bitmap) {
        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
            return bitmap.getRowBytes() * bitmap.getHeight();
        } else {
            return bitmap.getByteCount();
        }
    }
    

提交回复
热议问题