string imagePath = "C:\path\to\image.png"; BitmapImage bitmapImage = new BitmapImage(new Uri(imagePath)); Image imageControl = new Image(); imageControl.Source = bitmapImage;
byte[] imageData = GetImageData(); BitmapSource bitmapSource = BitmapSource.Create( width, height, dpiX, dpiY, pixelFormat, palette, imageData, stride); using (FileStream stream = new FileStream("output.png", FileMode.Create)) { PngBitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(bitmapSource)); encoder.Save(stream); }Package library: PresentationCore.dll and PresentationFramework.dll (for PngBitmapEncoder)