Why does reading and writing a JPEG with Java ImageIO reduce the file size?

999 Views Asked by At

I am using Java's javax.imageio.ImageIO to read contents from my FlashAir 32Gb (2nd gen) and to write them to my local hard drive. I can read and save the files, but I noticed that the ones in the hard drive are much smaller than the originals in the SD Card. Any ideas of why this is happening? This is the code that I use:

URL imageURL = new URL("http://192.168.0.1/DCIM/100__TSB/IMG_0001.JPG");
File dest = new File("/home/me/Pictures/FlashAir/IMG_0001.JPG");
BufferedImage image = ImageIO.read(imageURL);
ImageIO.write(image, "JPG", dest);

The images save to the local hard drive are fine, but they are about 1/3 of the original size.

1

There are 1 best solutions below

0
On BEST ANSWER

That code isn't just copying (reading and saving) files. It's decoding the images, and then re-encoding them at the default JPEG compression rate (which, judging by the JPEGImageWriteParam documentation, is 0.75).

If you want to change the compression level, check out this question.

If you're trying to copy the files exactly, don't use ImageIO at all.