如何使用高度宽度和类型android计算图像的大小

时间:2014-08-27 09:59:28

标签: android

如果我们知道图片的heightwidthMIME typebitmap,我们如何计算其尺寸?

截至目前,bitmap未分配。我使用inJustDecodeBounds来获取heightwidthMime type

Android中是否有某些特定方法,或者我们是否使用某些数学方法?

1 个答案:

答案 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()获取位图。