Get size of Bitmap Android [duplicate]

亡梦爱人 提交于 2020-01-02 01:03:23

问题


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?


回答1:


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?




回答2:


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);
}


来源:https://stackoverflow.com/questions/6833909/get-size-of-bitmap-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!