Get size of Bitmap Android [duplicate]
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, dec开发者_如何转开发ryptedData .length); //decoding bytearrayoutputstream to bitmap
Any suggestions?
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?
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);
}
精彩评论