Tôi đang cố gắng giảm kích thước bitmap bằng cách sử dụng phương pháp nén.Nén bitmap không thay đổi kích thước byte bitmap
Đây là mã của tôi:
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;
}
Khi tôi kiểm tra các bản ghi của tôi tôi nhận được:
11-28 11:10:38.252: I/before compress(2429): 374544
11-28 11:10:38.262: I/after compress(2429): 374544
Tại sao nén không hoạt động?
UPDATE:
Tôi đã thử mã này:
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;
}
Tuy nhiên số lượng byte cùng
11-28 11:33:04.335: I/before compress(3472): 374544
11-28 11:33:04.395: I/after compress 2(3472): 374544
vui lòng tham khảo follwing liên kết http://stackoverflow.com/questions/8417034/how-to-make-bitmap -compress-without-change-the-bitmap-size – prakash
Không phải vấn đề của tôi. Tôi không muốn chia tỷ lệ bitmap của mình chỉ để giảm kích thước trong bộ nhớ bằng cách thay đổi là quilaty. – dasdasd
Có phải giải pháp được tìm thấy cho vấn đề này không? Tôi đang đối mặt với cùng một vấn đề ở đây. – Prateek