Search code examples
windowsexifplatformuwpuniversal

Exif tags on universal Windows Platform C#


How do I add Tags to a jpeg picture on UWP (universal Windows Platform) / Windows Phone 10. WindowsBase and PresentationCore not available.


Solution

  • Here is an example about how to write the Artist exif tag to a jpeg image in Windows Runtime.

    You can find all of the EXIF tag ids in this web page:

    http://www.exiv2.org/tags.html

            var src = await KnownFolders
                            .PicturesLibrary
                            .GetFileAsync("210644575939381015.jpg");
    
            using (var stream = await src.OpenAsync(FileAccessMode.ReadWrite))
            {
                var decoder = await BitmapDecoder.CreateAsync(stream);
    
                var encoder = await BitmapEncoder.CreateForTranscodingAsync(stream, decoder);
    
                // var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, stream);
    
                var list = new List<KeyValuePair<string, BitmapTypedValue>>();
    
                var artist = new BitmapTypedValue("Hello World", Windows.Foundation.PropertyType.String);
    
                list.Add(new KeyValuePair<string, BitmapTypedValue>("/app1/ifd/exif/{ushort=315}", artist));
    
                await encoder.BitmapProperties.SetPropertiesAsync(list);
    
                await encoder.FlushAsync();
    
                await stream.FlushAsync();
            }