如何将JPEG Metadata(在Java中)从一个图像文件中复制到另一个图像文件?

发布于 2025-02-10 00:53:04 字数 1551 浏览 2 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小兔几 2025-02-17 00:53:04

JPEG的EXIF段为 clible长度,并包含TIFF结构。虽然从技术上讲可以在不重写容器文件的情况下更改EXIF(TIFF)数据,但这会限制您仅更改字段的选择,或者非常小心,以免字符串成长等。实际上,这不是很有用。

取而代之的是,我认为编辑EXIF元数据的大多数软件都会替换整个EXIF段,并且 copy 来自原始文件AS-IS的其他段。由于JPEG互换格式基于细分市场,因此相对容易做到这一点。

我相信MP4格式的情况相似。

类似于(伪代码):

file1 // original
file2 // modified copy
file3 // the new output

for each segment in file1
   if segment is exif
       copy exif from file2 to file3
   else 
       write segment to file3

 rename file3 to file1

因此,是的,如果您的计划应该可以起作用(尽管从技术上讲,它仍然“重写整个文件”)。

我完成了一些具有相似功能的低级元数据类,这可能是一个起点,但不要开箱即用。参见JPEGSegmentUtil and

但是,如果您的目标是操作后文件将是相同的,那么仅复制文件似乎更简单,更安全。


PS:还值得注意的是,EXIF数据中的某些字段与图像数据的解释(颜色空间,方向,维度)直接相关。因此,您可能应该仅复制字段的子集,或确保图像数据否则相同。

The Exif segment of a JPEG is variable length, and contains a TIFF structure. While it's technically possible to change Exif (TIFF) data without rewriting the container file, this limits you to change only a selection of fields, or be very careful so that strings don't grow etc.. In practice, this is not very useful.

Instead, I think most software that edits Exif metadata will replace the entire Exif segment, and copy the other segments from the original file as-is. As the JPEG interchange format is based on segments, this is relatively easy to do.

I believe the situation is similar for the MP4 format.

Something like (pseudo code):

file1 // original
file2 // modified copy
file3 // the new output

for each segment in file1
   if segment is exif
       copy exif from file2 to file3
   else 
       write segment to file3

 rename file3 to file1

So, yes, if this your plan, that should work (it will still technically "rewrite the whole file" though).

I have made a few low-level metadata classes with similar functionality that could be helpful as a starting point, but don't provide this out of the box. See JPEGSegmentUtil and JPEGSegmentImageInputStream.

However, if you goal is that the files will be identical after the operation, just copying the file seems a lot simpler and safer.


PS: It's also worth noting that some fields in the Exif data is directly related to the interpretation of the image data (color space, orientation, dimensions). So you should probably copy only a subset of fields, or make sure the image data is otherwise the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文