Get size of Bitmap Android [duplicate]

2020-08-17 06:48发布

Possible Duplicate:
Bitmap byte-size after decoding?

Is there anyway so I can get the size of this Bitmap?I've tried to use getByteCount() but I can't use it?

Bitmap bitmap = BitmapFactory.decodeByteArray(decryptedData , 0, decryptedData .length);    //decoding bytearrayoutputstream to bitmap

Any suggestions?

2条回答
别忘想泡老子
2楼-- · 2020-08-17 07:10

As you can see from the API, you can use

getWidth()
getHeight()

for the size of the Bitmap in pixels.

And if it is an array of bytes (8bit = 1byte) then just take decryptedData.length - offset and you know how many bytes are in the Bitmap.

Or am I missing something here?

查看更多
贪生不怕死
3楼-- · 2020-08-17 07:24

If the image is locally stored you can do the following

public long getImageLength(String absFileName)
{        
    File file = new File(absFileName);
    return file.length();
}

/**
 * From "http://stackoverflow.com/questions/2169649/open-an-image-in-androids-built-in-gallery-app-programmatically"
 * uri - data stored in an Intent returned from an application such as Gallery or Camera
 */
private String getAbsPath(Uri uri) 
{
    String[] projection = { MediaStore.Images.Media.DATA };
    Cursor cursor = managedQuery(uri, projection, null, null, null);
    int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
    cursor.moveToFirst();
    return cursor.getString(column_index);
}
查看更多
登录 后发表回答