我可以从 BufferedImage 获取原始图像吗?
我有一个 BufferedImage 实例:(仅一个示例)
BufferedImage image = ImageIO.read(new URL("http://www.google.com/intl/en_ALL/images/srpr/logo1w.png"));
现在,我只知道如何将此
ImageIO.write(image,"jpg", file); //or ImageIO.write(image,"png", file);
BufferedImage 保存到文件中,但该文件是 ZIPed,不等于原始图像大小。
我可以从 BufferedImage 实例获取原始图像 ByteArray 或 OutputStream 吗?
i has a BufferedImage instance: (only a example)
BufferedImage image = ImageIO.read(new URL("http://www.google.com/intl/en_ALL/images/srpr/logo1w.png"));
now,i only know use
ImageIO.write(image,"jpg", file); //or ImageIO.write(image,"png", file);
to save this BufferedImage to a file, but this file is ZIPed,not equal original image size.
can I get original image ByteArray or OutputStream from BufferedImage instance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简而言之:不。
Java 将图像转换为内部表示,并在读写时转换文件。
最好的选择是读取字节数组中的文件(或临时文件),然后从那里创建图像。保存文件时,返回到原始字节数组或临时文件。
In short : no.
Java converts the images to an internal representation and converts the files on reading and writing.
Your best bet will be to read the files in a byte array (or to a temporary file), create the image from there. and when saving the file, go back to the original bytearray or tempfile.