在我的应用程序中使用WPF的RenderTargetBitmap将大画布保存到位图中。图像尺寸较大时,图像看起来模糊。尺寸较小,工作正常。我用96 dpi创建位图,下面的代码用于将画布保存为位图。
RenderTargetBitmap bitamp = new RenderTargetBitmap(
(int)bounds.Width,
(int)bounds.Height,
96,
96,
System.Windows.Media.PixelFormats.Pbgra32);
//Create Drawing Visual.
DrawingVisual drawingVisual = new DrawingVisual();
using (DrawingContext drawingContext = drawingVisual.RenderOpen())
{
VisualBrush visualBrush = new VisualBrush(canvas);
//Draw rectangle filled with canvas.
drawingContext.DrawRectangle(visualBrush, null, new Rect(new Point(), bounds.Size));
}
//Render drawing visual to bitmap.
bitamp.Render(drawingVisual);
//Create instance of JpegBitmapEncoder
JpegBitmapEncoder jpgEncoder = new JpegBitmapEncoder();
//Add bitmap.
jpgEncoder.Frames.Add(BitmapFrame.Create(bitamp));
//Create new file and get stream from that.
using (Stream stream = File.Create(fileName))
{
//Save Image.
jpgEncoder.Save(stream);
}
如何解决这个问题?
答案 0 :(得分:0)
我不知道确切的条件,但JpegBitmapEncoder可能会产生模糊的元素轮廓。所以我建议改用PngBitmapEncoder。