截图PNG编码无法正常工作

时间:2014-06-17 14:34:29

标签: c# .net wpf

我正在创建一个截图程序,图片保存为jpg和BMP。问题是当我保存为PNG时。空白变成灰色,黑色也有点怪异。它有点模糊。任何人都知道可能导致这种情况的原因是什么?

不工作Png编码

    private void SaveAsPNG(String filePath)
    {
        int width = Screenshot.PixelWidth ;
        int height = Screenshot.PixelHeight;

        using (FileStream stream = new FileStream(filePath, FileMode.Create))
        {

            PngBitmapEncoder encoder = new PngBitmapEncoder();   
            encoder.Interlace = PngInterlaceOption.On;
            encoder.Frames.Add(BitmapFrame.Create(Screenshot));
            encoder.Save(stream);
        }
    }

使用BMPEncoding

    private void SaveAsBMP(String filePath)
    {
        int width = Screenshot.PixelWidth;
        int height = Screenshot.PixelHeight;

        using (FileStream stream = new FileStream(filePath, FileMode.Create))
        {
            BmpBitmapEncoder encoder = new BmpBitmapEncoder();
            encoder.Frames.Add(BitmapFrame.Create(Screenshot));
            encoder.Save(stream);
        }

    }

0 个答案:

没有答案
相关问题