public static byte[] AddMetadata(byte[] data, WallpaperInfo info) { using (var stream = new MemoryStream(data)) { var decoder = new JpegBitmapDecoder( stream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad); var metadata = decoder.Metadata; if (metadata is null) { metadata = new BitmapMetadata("jpg"); } metadata.Copyright = info.Copyright; metadata.Title = info.Title; var frame = decoder.Frames[0]; var encoder = new JpegBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(frame, frame.Thumbnail, metadata, frame.ColorContexts)); using (var outputStream = new MemoryStream()) { encoder.Save(outputStream); return(outputStream.ToArray()); } } }
public static void SaveToFile(byte[] data, WallpaperInfo info) { using (var stream = File.OpenWrite(info.FullFileName)) { //data = SetMetadata(data, info); stream.Write(data, 0, data.Length); } }