设置 JPEG 元数据 - 实现问题
通过之前的研究,我发现在图像上设置元数据属性并不难。例如,我可以将 JPEG 图像读入 Bitmap 对象,并通过图像的 SetPropertyItem 方法更改其“原始拍摄”日期(我也已经研究了执行此操作的格式和枚举)。
然而,虽然实际的元数据部分看起来很简单,但我面临着一些令人恼火的实现问题:
1)当我在位图上调用 Save() 时,似乎没有使用图像的原始编码设置。结果,压缩级别发生变化(大概是某个默认值);我可以看到在 Save() 调用后文件大小大大缩小。我知道您可以在调用 Save() 中自定义图像的编码设置,但说实话,我只想更改图片的元数据;是否有任何简单的方法可以使用原始编码设置保存图像?即使我可以在 Save() 调用中直接引用图像的现有编码设置,这也会有所帮助。
2)显然,当您将原始文件读入 Bitmap 对象时,原始文件被锁定。因此,我无法将图像保存在其原始文件名下,而无需进行大量处理:目前,我将从文件中读取的图像绘制到屏幕外位图上,处理原始图像,然后保存屏幕外位图。同样,当我只想更新图像文件中的元数据时,这似乎是一项非常多的额外工作。
您可以提供的任何建议将不胜感激...我必须做的工作量只是为了更新 JPEG 文件的元数据(其中大部分与实际的元数据更改无关)让我想知道我是否缺少一些更简单或更好的方法来做到这一点。
Through prior research, I've found that is isn't too hard to set the MetaData properties on an image. For example, I can read a JPEG image into a Bitmap object and change its "Original Taken" date through the image's SetPropertyItem method (I've already researched the format and enumeration for doing this, too).
However, although the actual MetaData part seems easy, I am faced with a couple of irritating implementation issues:
1) When I call Save() on the bitmap, it doesn't seem that the image's original encoding settings are used. As a result, the compression level changes (presumably to some default value); I can see the file size shrink considerably after my Save() call. I know that you can customize the encoding settings for an image within the call to Save(), but honestly, I only want to change the picture's metadata; isn't there any easy way to just save the image using its original encoding settings? Even if I could directly reference the image's existing encoding settings in the Save() call, that would help.
2) Apparently, the original file is locked when you read it into a Bitmap object. As a result, I can't save the image under its original file name without a lot of messing around: currently, I'm drawing the image I read from file onto an offscreen bitmap, disposing of the original image, and then saving the offscreen bitmap. Again, this seems like an awful lot of extra work when all I want to do is update the metadata in an image file.
Any suggestions you can offer would be most appreciated... the amount of work I'm having to do just to update a JPEG file's meta data (most of which has nothing to do with the actual metadata change) leads me to wonder if I'm missing some easier or better ways of doing this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您要做的是编辑 EXIF 数据。您现在正在做的是重新压缩图像,这将导致质量损失,正如您所注意到的。
请参阅此代码示例以编辑 EXIF: http://www.dreamincode.net/code/snippet3144.htm
What you want to do is edit the EXIF data. What you are doing now is recompressing the image, and this will cause quality loss, as you have noticed.
See this code sample for editing EXIF: http://www.dreamincode.net/code/snippet3144.htm