Canvas to Bitmap
Posted: 12 Oct 2015, 18:03
Hi guys, another question, is there any way to convert a canvas to an image? in standrd wpf I'd do something like this:
(which comes from http://stackoverflow.com/questions/2141 ... -sharp-wpf)
Code: Select all
Rect bounds = VisualTreeHelper.GetDescendantBounds(canvas);
double dpi = 96d;
RenderTargetBitmap rtb = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, dpi, dpi, System.Windows.Media.PixelFormats.Default);
DrawingVisual dv = new DrawingVisual();
using (DrawingContext dc = dv.RenderOpen())
{
VisualBrush vb = new VisualBrush(cnvs);
dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
}
rtb.Render(dv);