Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write XMP "People Tagged" in Universal Apps [UWP]

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

like image 303
Cassius Avatar asked Oct 19 '22 14:10

Cassius


1 Answers

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));
like image 114
Sebastian B Avatar answered Oct 22 '22 00:10

Sebastian B