自API 12以来,有一个有用的方法bitmap.getByteCount()
。但是在API 11中如何获得相同的值?
自API 12以来,有一个有用的方法bitmap.getByteCount()
。但是在API 11中如何获得相同的值?
正如dmon所提到的,根据这个问题下的评论,bitmap.getByteCount()
只是一个方便的方法,返回bitmap.getRowBytes() * bitmap.getHeight()
。因此,你可以使用自定义的方法代替它:
public static long getSizeInBytes(Bitmap bitmap) {
return bitmap.getRowBytes() * bitmap.getHeight();
}
int bitmapByteCount=BitmapCompat.getAllocationByteCount(bitmap)
或者,如果您希望自己完成:
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();
}