2

I want to do something like this: I have a Canvas with a VisualBrush as background. This Canvas is too large to print it. I want to convert it in something like a Bitmap with given dpi and add it to a page for printing purpose. My question is:

What is the best way to convert a Canvas in a bitmap like format, which i can add to a Page in WPF with given dpi?

Mehno
  • 868
  • 2
  • 8
  • 21
  • You didn't search StackOverflow for something like "wpf print canvas"? – Clemens Mar 16 '16 at 14:34
  • Oh i've done a lot of searching. The most common way i've found is: http://www.codeproject.com/Articles/339416/Printing-large-WPF-UserControls Bit this way ( to convert a canvas) is a little bit strange. I'am particular interested in the converting and not in the printing process. – Mehno Mar 16 '16 at 14:39
  • 1
    From the very first search result: http://stackoverflow.com/a/14153923/1136211. – Clemens Mar 16 '16 at 14:41
  • So there is no better way than going through rendertargetbitmap and an encoder? I thought there would be a better solution. Png uses some discrete cos. transform to compress the data...it don't know why i should do this, if i need only the bitmap in a page. But thank you for this link! – Mehno Mar 16 '16 at 14:47
  • RenderTargetBitmap is a bitmap. No need to encode it. The link should just give you an idea what to look for. It doesn't provide a complete solution. – Clemens Mar 16 '16 at 14:48

1 Answers1

1

1)- Convert your Convas to Writeablebitmap, look this :The fastest way to convert canvas to the writeablebitmap in WPF?

2) -Then Convert Writeablebitmap to any image, try this : Converting WriteableBitmap to Bitmap in C#

You can make one method to this.

Community
  • 1
  • 1
  • 1
    Except that there is no need for a conversion from RenderTargetBitmap to WriteableBitmap. RenderTargetBitmap is already a BitmapSource. – Clemens Mar 16 '16 at 18:59
  • Certainly, but the most important is the solution itself –  Mar 16 '16 at 19:47