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
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();
}