反正是有這樣我就可以得到這個位圖的大小,我試圖用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);
}
這是不正確的!文件大小與位圖大小無關。 大多數圖片都是壓縮的,實際的位圖大小通常較大。 – donald
什麼是managedQuery? –
@stema,@ ThiefMaster;我認爲,當你把一個問題作爲重複的時候,然後在對這個問題的評論中,你應該給出它是一個重複的原始問題的鏈接,以便那些正在尋找這樣的問題的答案的其他人將會從中受益從中。 –