简体   繁体   English

为什么使用ImageIO下载的文件比浏览器下载的文件小?

[英]Why is file downloaded using ImageIO smaller than browser downloaded file?

The code below downloads an image from the specified URL. 下面的代码从指定的URL下载图像。 When the same image is saved locally from the browser, it is significantly larger than the one downloaded programmatically by about a factor of 66%. 当从浏览器本地保存同一图像时,它比以编程方式下载的图像大得多,约为66%。

Although the code does not explicitly specify any parameters about the size, why is the downloaded file smaller than the one downloaded from the browser? 尽管代码未明确指定有关大小的任何参数,但是为什么下载的文件比从浏览器下载的文件小?

BufferedImage buffImage = ImageIO.read(new URL("random url to an image"));
ImageIO.write(buffImage, "jpg", new File("MyAppDl.jpg"));

EDIT: Weird ... it isn't consistent; 编辑:很奇怪...这是不一致的; on a different URL the thumbnail is distinctly smaller 在不同的URL上,缩略图明显较小

Just a guess: the brower loads the file "as is" ... your code reads the file into a data structure and then writes it again to a file. 只是一个猜测:浏览器“按原样”加载文件...您的代码将文件读取到数据结构中,然后再次将其写入文件中。 Most probably it appls default compression that might be higher then the orginal used ratio. 最有可能的是,它应用了默认压缩,该压缩可能会高于原始使用比率。

If you want the original file do not use BufferedImage and ImageIO but read/write it with plain streams. 如果要原始文件,请不要使用BufferedImageImageIO而应使用普通流对其进行读写。

The ImageIO version is being uncompressed and re-compressed with a different quality setting. 正在使用其他质量设置对ImageIO版本进行解压缩和重新压缩。 Don't do this, use the regular Stream classses that don't manipulate the data and just pass it through un-interpreted. 不要这样做,请使用不处理数据的常规Stream ,而只将其传递给未解释的数据。

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

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