操作图像而不删除其 EXIF 数据
使用 imageIO,我通常会遇到转换图像文件的问题,覆盖它后,它会丢失所有 EXIF 数据。有没有什么方法可以保留它,而无需先提取它、缓存它,然后重置它?
Using imageIO, I usually have the problem of transforming an image file, and after overwriting it, it loses all of its EXIF data. Is there any way to preserve it without first extracting it, caching it, and then resetting it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ImageIO 本身确实具有此功能,但您需要使用 ImageReader 而不是 ImageIO.read:(
您可能还想检查此类阅读器是否存在)。
然后你需要设置输入:
现在你可以保存你的元数据:
然后读取图像:
当你想保存新图像时,你应该使用 ImageWriter:
因为它是老话题,我想这个答案有点太晚了,但是可能会对其他人有所帮助,因为该主题仍然可以在谷歌上搜索。
ImageIO do have this functionality itself, but instead of ImageIO.read you will need to use ImageReader:
(you may want to also check if such reader exists).
Then you need to set the input:
Now you may save your metadata:
And then read the image:
When you want to save new image, you should use ImageWriter:
As it's old topic, I guess this answer is a bit too late, but may help others as this topic is still googlable.
这是我的解决方案,结合使用 ImageIO< /a>、Imgscalr 和 Apache commons-imaging。遗憾的是(2016 年 5 月)没有一个库将读取图像与其元数据结合起来,这使得内存使用可能相当过多;欢迎改进。
Here is my solution using a combination of ImageIO, Imgscalr and Apache commons-imaging. It's a pity there's (May 2016) no single library which combines reading the image with its metadata , making this probably rather excessive on memory usage; Improvements welcome.