Click here to Skip to main content
13,088,305 members (54,584 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi people,
My problem is that. If width is less than 6000 not problem, everything is okay, but if greater, then appears my problem. Image is distorted. Some shapes are not shown, white shape turn into black etc. (like this[^])

I tried to separate into subimages, but it didn't work.

Thanks in advance.

public void ExportToPng(Canvas canvas, string path, Size size)
    if (path == null) return;
    var rect = new Rect(size);
    Render(canvas, size, path);

private void Render(Visual visual, Size size, string path)
    double dpi = 128;
    double scale = dpi / 96;
    RenderTargetBitmap renderBitmap =
        new RenderTargetBitmap(
        (int)(size.Width * scale),
        (int)(size.Height * scale),
    BitmapEncoder encoder = new JpegBitmapEncoder();
    using (FileStream outStream = new FileStream(path, FileMode.Create))
Posted 22-Apr-13 23:24pm
Updated 24-Apr-13 21:38pm
Matej Hlatky 23-Apr-13 13:56pm
What about to saving Canvas content as SVG?
MahmutKoyuncu 24-Apr-13 4:41am
Thanks for your response.Does WPF support SVG? I couldn't find anything about saving canvas or visual as SVG?
Matej Hlatky 24-Apr-13 4:54am
No, it was just my idea as a workaround.
You need to code this by yourself - iterate over all Canvas children, get their absolute position, size and other visual properties and print appropriate SVG element (text, rect, circle, ...) into output stream.
Good luck!

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

There are lots of different ways of doing this, you might try this:[^]

The easiest solution would ofcourse be to save the imaqge in some vector format, but you would have to build the function by had, or so it seems:[^]

You could use the drawing visual calass to print it though:[^]

This might also be worth a go:[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 25 Apr 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100