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?

Community
  • 1
  • 1
hardartcore
  • 16,886
  • 12
  • 75
  • 101
  • 4
    @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. – Shirish Herwade Dec 27 '12 at 07:04

2 Answers2

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?

das_weezul
  • 6,082
  • 2
  • 28
  • 33
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 "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);
}
Paradius
  • 7,949
  • 11
  • 32
  • 38