1: using (Stream writerbitmapStream = new System.IO.FileStream(imagePath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
2: {
3: BitmapDecoder bitmapDecoder = JpegBitmapDecoder.Create(writerbitmapStream, BitmapCreateOptions.None, BitmapCacheOption.Default);
4: BitmapEncoder bitmapEncoder = new JpegBitmapEncoder();
5: BitmapFrame bitmapFrame = bitmapDecoder.Frames[0];
6: BitmapMetadata bitmapMetadata = bitmapFrame.Metadata.Clone() as BitmapMetadata;
7:
8: System.Collections.ObjectModel.ReadOnlyCollection<string> autori =
9: new System.Collections.ObjectModel.ReadOnlyCollection<string>(
10: new List<string>(new string[] { "Pietro Libro", "Pinco Pallino" }));
11: System.Collections.ObjectModel.ReadOnlyCollection<string> keywords =
12: new System.Collections.ObjectModel.ReadOnlyCollection<string>(
13: new List<string>(new string[] { "Desert", "Sand" ,"Enviroment"}));
14:
15: bitmapMetadata.Title = "Desert";
16: bitmapMetadata.Copyright = "Copyright 123.";
17: bitmapMetadata.Author = autori;
18: bitmapMetadata.Keywords = keywords;
19: bitmapMetadata.Rating = 100;
20: bitmapMetadata.Subject = "---";
21: bitmapMetadata.Rating = 5;
22: bitmapMetadata.ApplicationName = "Custom WPF Application";
23: bitmapMetadata.CameraModel = "Camera Brand 5600";
24: bitmapMetadata.CameraManufacturer = "Brand";
25:
26: bitmapEncoder.Frames.Add(BitmapFrame.Create(bitmapFrame, bitmapFrame.Thumbnail, bitmapMetadata, bitmapFrame.ColorContexts));
27:
28: using (Stream outputFile = File.Open(@"path_output", FileMode.Create, FileAccess.ReadWrite))
29: {
30: bitmapEncoder.Save(outputFile);
31: }
32: writerbitmapStream.Close();
33: }