我試圖通過使用壓縮方法來減少位圖大小。位圖壓縮不會更改位圖字節大小
這是我的代碼:
public Bitmap compressImage(Bitmap image) {
Bitmap immagex = image;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Log.i("before compress", immagex.getByteCount()+"");
boolean compress = immagex.compress(Bitmap.CompressFormat.JPEG, 10, baos);
if(compress)
Log.i("after compress", immagex.getByteCount()+"");
else
Log.i("bad compress", "bad compress");
return immagex;
}
當我檢查我的日誌我得到:
11-28 11:10:38.252: I/before compress(2429): 374544
11-28 11:10:38.262: I/after compress(2429): 374544
爲什麼壓縮不起作用?
UPDATE:
我試過這段代碼:
public Bitmap compressImage(Bitmap image) {
Bitmap immagex = image;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Log.i("before compress", immagex.getByteCount()+"");
boolean compress = immagex.compress(Bitmap.CompressFormat.JPEG, 10, baos);
Log.i("after compress 2", decodeSampledBitmapFromByte(image.getWidth(), image.getHeight(), baos.toByteArray()).getByteCount()+"");
return immagex;
}
還是一樣的字節數
11-28 11:33:04.335: I/before compress(3472): 374544
11-28 11:33:04.395: I/after compress 2(3472): 374544
請參考以下鏈接http://stackoverflow.com/questions/8417034/how-to-make-bitmap -compress-without-change-the-bitmap-size – prakash
它不是我的問題。 我不想縮放我的位圖只是爲了減少內存中的大小通過改變是很容易。 – dasdasd
找到了解決此問題的解決方案?我在這裏面對同樣的問題。 – Prateek