在C#中将XMP元数据添加到JPEG

时间:2016-07-08 05:23:21

标签: c# facebook metadata jpeg xmp

我现有jpg照片,宽高比为2:1,不包含任何XMP元数据。使用C#,我想将类似于下面显示的xmp元数据添加到我的jpg照片中。目的是将这些照片上传到Facebook,并将其识别为360照片。

<rdf:Description rdf:about="" xmlns:GPano="http://ns.google.com/photos/1.0/panorama/">
<GPano:UsePanoramaViewer>True</GPano:UsePanoramaViewer>
<GPano:CaptureSoftware>Photo Sphere</GPano:CaptureSoftware>
<GPano:StitchingSoftware>Photo Sphere</GPano:StitchingSoftware>
<GPano:ProjectionType>equirectangular</GPano:ProjectionType>
<GPano:PoseHeadingDegrees>350.0</GPano:PoseHeadingDegrees>
<GPano:InitialViewHeadingDegrees>90.0</GPano:InitialViewHeadingDegrees>
<GPano:InitialViewPitchDegrees>0.0</GPano:InitialViewPitchDegrees>
<GPano:InitialViewRollDegrees>0.0</GPano:InitialViewRollDegrees>
<GPano:InitialHorizontalFOVDegrees>75.0</GPano:InitialHorizontalFOVDegrees>
<GPano:CroppedAreaLeftPixels>0</GPano:CroppedAreaLeftPixels>
<GPano:CroppedAreaTopPixels>0</GPano:CroppedAreaTopPixels>
<GPano:CroppedAreaImageWidthPixels>4000</GPano:CroppedAreaImageWidthPixels>
<GPano:CroppedAreaImageHeightPixels>2000</GPano:CroppedAreaImageHeightPixels>
<GPano:FullPanoWidthPixels>4000</GPano:FullPanoWidthPixels>
<GPano:FullPanoHeightPixels>2000</GPano:FullPanoHeightPixels>
<GPano:FirstPhotoDate>2012-11-07T21:03:13.465Z</GPano:FirstPhotoDate>
<GPano:LastPhotoDate>2012-11-07T21:04:10.897Z</GPano:LastPhotoDate>
<GPano:SourcePhotosCount>50</GPano:SourcePhotosCount>
<GPano:ExposureLockUsed>False</GPano:ExposureLockUsed>
</rdf:Description>

我现有的解决方案只是在EXIF元数据中将相机品牌和型号分别设置为“RICOH”和“RICOH THETA S”。虽然这有效,但我想使用xmp元数据,因此我可以指定Facebook识别的特定字段,例如InitialViewHeadingDegrees。

当前解决方案

public static Stream addThetaTags(Stream stream)
    {
        // Create image
        Image image = Image.FromStream(stream);

        PropertyItem make = (PropertyItem)FormatterServices.GetUninitializedObject(typeof(PropertyItem));
        make.Id = 0x010F;
        make.Len = 22;
        make.Type = 2;
        make.Value = new Byte[] { 82, 73, 67, 79, 72, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0 };

        PropertyItem model = (PropertyItem)FormatterServices.GetUninitializedObject(typeof(PropertyItem));
        model.Id = 0x0110;
        model.Len = 64;
        model.Type = 2;
        model.Value = new Byte[] { 82, 73, 67, 79, 72, 32, 84, 72, 69, 84, 65, 32, 83, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 0 };

        // Set make property to RICOH
        image.SetPropertyItem(make);

        //set model property to RICOH THETA S
        image.SetPropertyItem(model);

        //save image as stream
        Stream ms = new MemoryStream();
        image.Save(ms, ImageFormat.Jpeg);

        // If you're going to read from the stream, you may need to reset the position to the start
        ms.Position = 0;
        return ms;
    }

0 个答案:

没有答案