5

Using WIC I am able to write xmp info about people tagged: People Tagging Overview

Now I am trying to do the same in UWP but it is not working:

When I try only change a simple tag like "/xmp/Title" it is working.

But when I try to change "PersonDisplayName" or "Rectangle", it is not working.

Code Sample:

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);
        }
    }

Does anyone have ideas or suggestions?

Thanks

Cassius
  • 159
  • 1
  • 8
  • I can only see that you read a file (possible a image file) from your `InstalledLocation` and turn it to stream, then you use decoder and encoder of `Bitmap` to do something with this stream then restore it as a file, what you want to do with this file? – Grace Feng Feb 29 '16 at 09:12
  • 1
    I am trying to insert metadata in a bitmap in UWP, I am able to read all metadata . I am able to write all metadata in a bitmap , except the People Tag. In C++/Desktop application it is working using WIC but In UWP it is not working, – Cassius Feb 29 '16 at 12:17
  • 1
    I also tried for my current project to tag people but it did not work. Has anyone found a solution for this? – ctron Jul 11 '16 at 15:45

1 Answers1

3

This is working for me:

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));
Sebastian B
  • 404
  • 2
  • 8