There is a useful method bitmap.getByteCount()
since API level 12. But how to get same value in API 11?
Asked
Active
Viewed 3,444 times
3

Dmitry Zaytsev
- 23,650
- 14
- 92
- 146
2 Answers
19
As mentioned by dmon, according to the comments of this question bitmap.getByteCount()
is just a convenience method which returns bitmap.getRowBytes() * bitmap.getHeight()
. So you can use a custom method instead :
public static long getSizeInBytes(Bitmap bitmap) {
return bitmap.getRowBytes() * bitmap.getHeight();
}
-
1Like the commenters said in that answer, you don't need the if-else block. Just use the else bit. That way you don't need AndroidVersion. – dmon Jun 21 '12 at 13:52
7
It's best to just use the support library:
int bitmapByteCount=BitmapCompat.getAllocationByteCount(bitmap)
or, if you wish to do 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();
}

android developer
- 114,585
- 152
- 739
- 1,270