如果我们知道图片的height
,width
和MIME type
或bitmap
,我们如何计算其尺寸?
截至目前,bitmap
未分配。我使用inJustDecodeBounds
来获取height
,width
和Mime type
。
Android中是否有某些特定方法,或者我们是否使用某些数学方法?
答案 0 :(得分:0)
public static int getBitmapByteSize(Bitmap bitmap) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
return bitmap.getAllocationByteCount();
}
else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {
return bitmap.getByteCount();
}
else {
return bitmap.getRowBytes() * bitmap.getHeight();
}
}
从ImageView调用((BitmapDrawable)image.getDrawable()).getBitmap()
获取位图。