在我的應用程序中,我下載了一些圖像,並且想知道是否有任何方法可以獲取我已下載的位圖大小。這是一個簡單的問題,但我似乎無法通過Google找到解決方案。有什麼辦法來獲取位圖的存儲大小?
這裏是下載的代碼:
Bitmap b = BitmapFactory.decodeStream((InputStream) new URL(theImageUrl).getContent());
在我的應用程序中,我下載了一些圖像,並且想知道是否有任何方法可以獲取我已下載的位圖大小。這是一個簡單的問題,但我似乎無法通過Google找到解決方案。有什麼辦法來獲取位圖的存儲大小?
這裏是下載的代碼:
Bitmap b = BitmapFactory.decodeStream((InputStream) new URL(theImageUrl).getContent());
首先將位圖轉換爲字節[]那麼你可以得到位圖的大小
嘗試用泰豐下面的代碼
Bitmap bitmap = your bitmap object
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, stream);
byte[] imageInByte = stream.toByteArray();
long length = imageInByte.length;
File file = new File("infilename");
// Get the number of bytes in the file
long length = file.length();
謝謝,但我沒有使用File類。我正在使用Bitmap類。你是否建議將位圖轉換爲文件然後執行此操作? – NotACleverMan
然後在此處下載您的代碼下載代碼 – ingsaurabh
爲什麼你需要知道我是如何下載它的?我只是使用了一個Bitmap類。你知道:「位圖b =新的位圖();」 – NotACleverMan