简体   繁体   English

为什么用Java ImageIO读写JPEG会减小文件大小?

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

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. 我正在使用Java的javax.imageio.ImageIO从FlashAir 32Gb(第二代)中读取内容,并将其写入本地硬盘。 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. 我可以读取并保存文件,但是我注意到硬盘驱动器中的文件比SD卡中的原始文件小得多。 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/3。

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). 它先解码图像,然后以默认的JPEG压缩率(根据JPEGImageWriteParam文档判断为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. 如果您要尝试精确复制文件,请不要使用ImageIO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM