开发者

.NET: Saving Clipboard Image to PNG fails

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.Sav开发者_运维百科e(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.


I would first try something like ClipSpy to examine which application puts which type of content on the clipboard.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜