public void ExportToPng(Canvas canvas, string path, Size size) { if (path == null) return; canvas.Measure(size); var rect = new Rect(size); canvas.Arrange(rect); 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), dpi, dpi, PixelFormats.Pbgra32); renderBitmap.Render(visual); BitmapEncoder encoder = new JpegBitmapEncoder(); using (FileStream outStream = new FileStream(path, FileMode.Create)) { encoder.Frames.Add(BitmapFrame.Create(renderBitmap)); encoder.Save(outStream); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)