可能重复:
解码后的位图字节大小?
无论如何,我可以得到这个位图的大小吗?我尝试使用 getByteCount() 但我不能使用它?
Bitmap bitmap = BitmapFactory.decodeByteArray(decryptedData , 0, decryptedData .length); //decoding bytearrayoutputstream to bitmap
有什么建议么?
可能重复:
解码后的位图字节大小?
无论如何,我可以得到这个位图的大小吗?我尝试使用 getByteCount() 但我不能使用它?
Bitmap bitmap = BitmapFactory.decodeByteArray(decryptedData , 0, decryptedData .length); //decoding bytearrayoutputstream to bitmap
有什么建议么?
正如您从API中看到的,您可以使用
getWidth()
getHeight()
以像素为单位的位图大小。
如果它是一个字节数组(8bit = 1byte)decryptedData.length - offset
,那么你就知道位图中有多少字节。
或者我在这里错过了什么?
如果图像存储在本地,您可以执行以下操作
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);
}