在C#/ VB.NET中将EXIF元数据从TIF复制到JPEG

时间:2022-09-25 21:19:08

I would really appreciate if you could shed light on this problem. I have 2 images, one was created from TIF file with metadata, the other is an in-memory image that will be saved as jpeg. Then I use this routine to transfer exif metadata from first image to the second one (that is from the one created from tif file to the in-memory image):

如果你能说清楚这个问题,我真的很感激。我有2个图像,一个是从带有元数据的TIF文件创建的,另一个是将保存为jpeg的内存中图像。然后我使用这个例程将exif元数据从第一个图像传输到第二个图像(即从tif文件创建到内存中的图像):

For Each _p In image1.PropertyItems
   image2.SetPropertyItem(_p)
Next

And this works perfectly fine. All exif items are successfully copied. I confirmed this by using watches in debug mode. The problem comes when you save image2 as jpeg using this:

这完美无缺。所有exif项都已成功复制。我在调试模式下使用手表证实了这一点。使用以下方法将image2另存为jpeg时会出现问题:

    Dim eps As EncoderParameters = New EncoderParameters(1)
    eps.Param(0) = New EncoderParameter(Encoder.Quality, 85)
    Dim ici As ImageCodecInfo = GetEncoderInfo("image/jpeg")
    image2.Save("C:\1.jpg", ici, eps)

Only very few EXIF properties are saved with image2 jpeg file however, namely only camera model and camera maker. However If I save image2 as TIF, all properties from the original tif will be there. Can anyone explain why is that?

但是,只有极少数EXIF属性与image2 jpeg文件一起保存,即只有相机型号和相机制造商。但是,如果我将image2保存为TIF,则原始tif中的所有属性都将存在。谁能解释为什么会这样?

Thanks.

1 个解决方案

#1


Take a look at Exiv2Sharp - this wrapper around Exiv2 should provide what you're looking for.

看看Exiv2Sharp - 围绕Exiv2的这个包装应该提供你想要的东西。

#1


Take a look at Exiv2Sharp - this wrapper around Exiv2 should provide what you're looking for.

看看Exiv2Sharp - 围绕Exiv2的这个包装应该提供你想要的东西。