I have a weird issue with saving of clipboard image to png. When taking a screenshot with prtscr or snipping tool it works fine with Clipboard.GetImage() and PngBitmapEncoder. But when copying the image from Paint and doing the same I get a empty image as result. At least it looks empty when trying to view it, though it seems to contain valid PNG-image-data. When using the Jpeg-encoder it works fine. Whats the problem with PNG and Paint? Does it have anything to do with transparency?
Update to clarify: Im extracting an image successfully from the clipboard. I just cant save it to disc using the PNGEncoder if the image was copied from Paint in the first place. I can save paint-clipboard-images with the JpegEncoder though... but I want to use PNG.
BitmapSource source = Clipboard.GetImage();
PngBitmapEncoder enc = new PngBitmapEncoder();
enc.Frames.Add(BitmapFrame.Create(source));
enc.Save(stream);
Above code produces a image-file with invisible content, turns up completely black or white depending on the viewer (when copied from, ctrl-c, from Paint). Which leads me to think it has something to do with transparency...
Your problem looks very similar to the one I described here... the solution I suggested should probably work for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With