Black image when saving PNG from clipboard

I am trying to save a PNG image that has been copied to the clipboard, but it either becomes solid black or black around areas that should be transparent.

Here is the code I use to capture and save the image

var clipboardImage = (InteropBitmap)Clipboard.GetImage(); Image.SaveImage(clipboardImage, Path.Combine(Config.App.ApplicationDataImagesPath, string.Format("{0}.{1}", imageId, "png"))); public static void SaveImage(BitmapSource bitmapImage, string filename) { using (var fileStream = new FileStream(filename, FileMode.Create)) { var pngBitmapEncoder = new PngBitmapEncoder(); pngBitmapEncoder.Frames.Add(BitmapFrame.Create(bitmapImage)); pngBitmapEncoder.Save(fileStream); fileStream.Close(); fileStream.Dispose(); } } 

Does anyone have any idea why he won't look for PNG alpha channels?

thanks

Dan

Edit: I should mention that black images were executed when copying an image from Internet Explorer 9. Works great when copying an image from Chrome or Firefox. Any workarounds for IE9 issue?

+4
source share
1 answer

What happens if you just do this:

 Clipboard.GetImage().Save ("XXX.png", System.Drawing.Imaging.ImageFormat.Png); 

EDIT - For WPF, try the following:

 public static void SaveClipboardImageToFile(string filePath) { var image = Clipboard.GetImage(); using (var fileStream = new FileStream(filePath, FileMode.Create)) { BitmapEncoder encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(image)); encoder.Save(fileStream); } } 
+3
source

All Articles