Get size of Bitmap Android [duplicate]
Asked Answered
B

2

11

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?

Busybody answered 26/7, 2011 at 17:14 Comment(1)
@stema, @ ThiefMaster ; I think, when you close a question as duplicate, then in comment of that question, you should give the link of the original question of which it is a duplicate, so that, others who are searching answer to questions like this, will get benefit from it.Disembody
F
5

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?

Faltboat answered 26/7, 2011 at 17:19 Comment(0)
S
4

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 "https://mcmap.net/q/27045/-get-pick-an-image-from-android-39-s-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);
}
Stockist answered 26/1, 2012 at 16:21 Comment(2)
This is not correct! file size has nothing to do with bitmap size. Most pics are compressed, and the actual bitmap size is usually bigger.Cultivable
what is managedQuery?Hadj

© 2022 - 2024 — McMap. All rights reserved.