【问题标题】:In WPF 4.0: How to render to a (PNG) bitmap as good as to the window?在 WPF 4.0 中:如何渲染到(PNG)位图和窗口一样好?
【发布时间】:2012-08-04 13:47:41
【问题描述】:

我正在以另一种方式将我的 WPF (4.0) 视觉效果(矢量图)导出为某些图像格式...

    public void ExportImageTo(BitmapEncoder Encoder, Stream ExportStream, Visual SourceVisual, int Width, int Height)
    {
        var Result = new RenderTargetBitmap(Width, Height, WPF_DPI, WPF_DPI, PixelFormats.Default);
        Result.Render(Source);

        Encoder.Frames.Add(BitmapFrame.Create(Result));
        Encoder.Save(ExportStream);

        ExportStream.Flush();
        ExportStream.Close();
    }

问题在于,即使使用 PngBitmapEncoder(无损算法),它仍然会生成一些与屏幕上不同的小像素。

我认为这与 WPF 呈现文本或处理抗锯齿的方式有关,并且存在 UseLayoutRounding、SnapsToDevicePixels 和 BitmapScalingMode 等属性(注意:我没有在我的代码中使用这些属性)。

那么,我可以做些什么来使我导出的视觉效果看起来像在屏幕上呈现的视觉效果? 谢谢!

【问题讨论】:

    标签: .net wpf bitmap wpf-4.0


    【解决方案1】:

    显然,如果 WPF 以透明背景为目标,则 WPF 不会呈现 ClearType 文本(谷歌此:RenderOptions.ClearTypeHint)。我想知道使用 24 位图像格式(无 alpha 通道)是否会取得更好的成功。此外,宽度/高度与实际宽度/实际高度不同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-06-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-29
      • 1970-01-01
      相关资源
      最近更新 更多