【问题标题】:How to write XMP "People Tagged" in Universal Apps [UWP]如何在通用应用程序中编写 XMP“人标签”[UWP]
【发布时间】:2016-02-26 20:44:23
【问题描述】:

使用 WIC,我可以编写有关标记的人的 xmp 信息: People Tagging Overview

现在我尝试在 UWP 中做同样的事情,但它不起作用:

当我尝试只更改像“/xmp/Title”这样的简单标签时,它正在工作。

但是当我尝试更改“PersonDisplayName”或“Rectangle”时,它不起作用。

代码示例:

public async void SaveNewPeopleTagged(StorageFile file, string name , string rect)
    {
        try
        {
            using (IRandomAccessStream fileStream = await file.OpenAsync(FileAccessMode.ReadWrite),
                                       memStream = new InMemoryRandomAccessStream())
            {
                BitmapDecoder decoder = await BitmapDecoder.CreateAsync(fileStream);

                // Set the encoder's destination to the temporary, in-memory stream.
                BitmapEncoder encoder = await BitmapEncoder.CreateForTranscodingAsync(memStream, decoder);

                var propertySet = new Windows.Graphics.Imaging.BitmapPropertySet();

                BitmapTypedValue btName = new BitmapTypedValue(name, Windows.Foundation.PropertyType.String);
                //"/xmp/<xmpstruct>MP:RegionInfo/<xmpbag>MPRI:Regions/PersonDisplayName" **is not working**
                propertySet.Add("/xmp/RegionInfo/Regions/PersonDisplayName", btName);

                BitmapTypedValue btRect = new BitmapTypedValue(rect, Windows.Foundation.PropertyType.String);
                //"/xmp/<xmpstruct>MP:RegionInfo/<xmpbag>MPRI:Regions/Rectangle" **is not working**
                propertySet.Add("/xmp/RegionInfo/Regions/Rectangle", btRect);

                await encoder.BitmapProperties.SetPropertiesAsync(propertySet);
                //**Give a exception... "Value does not fall within the expected range."**

                //If I use only : propertySet.Add("/xmp/Title", ...); it is working

                await encoder.FlushAsync();
                await memStream.FlushAsync();
                memStream.Seek(0);
                fileStream.Seek(0);
                fileStream.Size = 0;
                await RandomAccessStream.CopyAsync(memStream, fileStream);

            }
        }
        catch (Exception err)
        {
            Debug.WriteLine(err.Message);
        }
    }

有人有想法或建议吗?

谢谢

【问题讨论】:

  • 我只能看到你从InstalledLocation 读取了一个文件(可能是图像文件)并将其转换为流,然后使用Bitmap 的解码器和编码器对此流进行处理然后把它恢复为一个文件,你想用这个文件做什么?
  • 我正在尝试在 UWP 的位图中插入元数据,我能够读取所有元数据。我可以将所有元数据写入位图中,除了人物标签。在 C++/桌面应用程序中,它使用 WIC 工作,但在 UWP 中它不工作,
  • 我也尝试为我当前的项目标记人员,但没有成功。有没有人找到解决方案?

标签: win-universal-app xmp


【解决方案1】:

这对我有用:

int n = 0; // nth entry
propertySet.Add("/xmp/<xmpstruct>MP:RegionInfo/<xmpbag>MPRI:Regions/<xmpstruct>{ulong=" + n + "}/MPReg:Rectangle", new BitmapTypedValue(rect, PropertyType.String));
propertySet.Add("/xmp/<xmpstruct>MP:RegionInfo/<xmpbag>MPRI:Regions/<xmpstruct>{ulong=" + n + "}/MPReg:PersonDisplayName", new BitmapTypedValue(name, PropertyType.String));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-15
    • 2016-08-02
    • 2015-04-10
    • 1970-01-01
    • 2019-07-08
    相关资源
    最近更新 更多