【发布时间】:2017-02-28 19:52:34
【问题描述】:
我正在尝试使用压缩方法来减小位图大小。
这是我的代码:
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
为什么压缩不起作用?
更新:
我试过这段代码:
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
【问题讨论】:
-
这不是我的问题。我不想缩放我的位图只是为了通过改变是 quilaty 来减少内存中的大小。
-
找到解决这个问题的方法了吗?我在这里面临同样的问题。
-
我面临同样的问题。实际上我的字节数组随着压缩参数的降低而增加