This documentation is archived and is not being maintained.

How to: Use an InPlaceMetadataWriter to Change Metadata

This example shows how you can modify metadata within an image without having to re-encode the image.

The following example uses an InplaceBitmapMetadataWriter to write metadata into an image. For the complete sample, see BitmapMetadata Sample.

Stream pngStream = new System.IO.FileStream("smiley.png", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
PngBitmapDecoder pngDecoder = new PngBitmapDecoder(pngStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame pngFrame = pngDecoder.Frames[0];
InPlaceBitmapMetadataWriter pngInplace = pngFrame.CreateInPlaceBitmapMetadataWriter();
if (pngInplace.TrySave() == true)
{ pngInplace.SetQuery("/Text/Description", "Have a nice day."); }
pngStream.Close();
Show: