我正在创建一个截图程序,图片保存为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);
}
}