Canvas to image


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. Rect bounds = VisualTreeHelper.GetDescendantBounds(canvas);
  2. double dpi = 96d;
  3.  
  4.  
  5. RenderTargetBitmap rtb = new RenderTargetBitmap((int)bounds.Width, (int)bounds.Height, dpi, dpi, System.Windows.Media.PixelFormats.Default);
  6.  
  7.  
  8. DrawingVisual dv = new DrawingVisual();
  9. using (DrawingContext dc = dv.RenderOpen())
  10. {
  11. VisualBrush vb = new VisualBrush(cnvs);
  12. dc.DrawRectangle(vb, null, new Rect(new Point(), bounds.Size));
  13. }
  14.  
  15. rtb.Render(dv);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.