ReaderSvgRenderToBitmap Method (Int32, Int32, Brush) |
Namespace: Ab2d
public BitmapSource RenderToBitmap( int customWidth, int customHeight, Brush backgroundBrush )
The following example uses the RenderToBitmap(Brush) method to render the read svg file to wpfBitmap:
var readerSvg = new Ab2d.ReaderSvg(); readerSvg.Read(@"c:\mySample.svg"); // Render to bitmap var wpfBitmap = readerSvg.RenderToBitmap(Brushes.White);
The next example uses this method to render the read svg file to image with custom size and saves it to disk:
var readerSvg = new Ab2d.ReaderSvg(); readerSvg.Read(@"c:\mySample.svg"); // Render to bitmap with 1024 width - height will be set automatically so that the // Image aspect ratio is preserved var wpfBitmap = readerSvg.RenderToBitmap(1024, 0, Brushes.White); var encoder = new System.Windows.Media.Imaging.PngBitmapEncoder(); // Uncomment to save to jpg //var encoder = new JpegBitmapEncoder(); //encoder.QualityLevel = 85; encoder.Frames.Add(System.Windows.Media.Imaging.BitmapFrame.Create(wpfBitmap)); using (var stream = System.IO.File.OpenWrite("c:\\svgImage.png")) { encoder.Save(stream); }