Click or drag to resize
AB4D logo

ReaderSvgRenderToBitmap Method (Brush)

Renders the read svg objects into bitmap. Bitmap will have the same size as read svg object and will be rendered at 96 dpi.

Namespace:  Ab2d
Assembly:  Ab2d.ReaderSvg (in Ab2d.ReaderSvg.dll) Version: 7.1.7295.1040
Syntax
C#
public BitmapSource RenderToBitmap(
	Brush backgroundBrush
)

Parameters

backgroundBrush
Type: System.Windows.MediaBrush
background brush

Return Value

Type: BitmapSource
BitmapSource
Examples

The following example uses this 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 the RenderToBitmap(Int32, Int32, Brush) 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);
}
See Also