I am using Bitmap's compress()
method to compress my images with the help of following code:
ByteArrayOutputStream baos;
Bitmap img = BitmapFactory.decodeFile(imgs[i].getAbsolutePath());
img.compress(Bitmap.CompressFormat.JPEG, compFactor, baos);
byte[] compImgBytes;
compImgBytes = baos.toByteArray();
OutputStream out1 = new BufferedOutputStream(new FileOutputStream(
new File(dir.getString("dir", null) + File.separator +
String.valueOf(imgsName) + ".jpg")));
out1.write(compImgBytes);
Problem is, when I use 100 as a compression factor (compFactor = 100
) for this code, the size of the resultant image is larger than the image being compressed. All I was trying to do was compress the image with max quality as per Android documentation for the Bitmap class.
Why is the resultant image's size greater than original image's size? Am I missing something?
Passing in 100
for the quality indicates:
100 meaning compress for max quality
So that means the compressor will do very little compression of the raw bytes... the images you are loading are presumably saved with more compression. Thus your newly compressed image is larger than your original images.