0

I'm exporting my WPF (4.0) visuals (vector diagrams) to some image formats in the next way...

    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();
    }

The problem is that even using a PngBitmapEncoder (loseless algorithm) it still generates some little pixels that differs from those in the screen.

I think it is related with the way WPF renders text or deals with anti-aliasing and for which exists properties like UseLayoutRounding, SnapsToDevicePixels and BitmapScalingMode (note: I'm not using those properties on my code).

So, what can I do to make my exported visuals look like those rendered on screen? Thanks!

Néstor Sánchez A.
  • 3,848
  • 10
  • 44
  • 68

1 Answers1

1

Apparently WPF doesn't render ClearType text if it's targeting a transparent background (google this: RenderOptions.ClearTypeHint). I wonder if you would have better success with a 24bit image format (no alpha channel). Also, Width/Height are not the same as ActualWidth/ActualHeight.

Brannon
  • 5,324
  • 4
  • 35
  • 83