To render an Leadtools.Svg.SvgDocument to a target device:
Obtain an instance of IRenderingEngine
Set up the rendering options using SvgRenderOptions
An IRenderingEngine can be obtained using one of the following methods:
SvgRenderOptions contains the following properties:
The destination rectangle, in pixel coordinates. The SVG document will be rendered to fit and center inside this rectangle. SvgRenderOptions.Transform will be applied to this rectangle.
The clipping rectangle, in pixel coordinates. The engine will apply this clipping into Bounds to exclude all or parts of the objects that do not fit. The transformation set in SvgRenderOptions.Transform will not be applied to this rectangle.
The transformation to be applied. This is a LeadMatrix instance that you can use for zooming, translation and rotation of the final document.
Use BackgroundColor to fill the background of the transformed destination rectangle.
The following code illustrates how to render a document by automatically checking its flat and bounds state:
void RenderDocument(IRenderingEngine engine, SvgRenderOptions options, SvgDocument svgDocument)
// If the document is not flat, flatten it and automatically calculate its size
// If the document does not have a valid bounds, calculate it now automatically
var svgBounds = svgDocument.Bounds;
// Now, render the document
If the Leadtools.Svg.SvgDocument will be rendered once, it is best to leave the optimization as is. However, if the document will be rendered many times (for example, it is being viewed in an ImageViewer control, then it is best to cache this data to enhance speed. This can easily be achieved by using BeginRenderOptimize before setting the document in the viewer.
BeginRenderOptimize and EndRenderOptimize use an internal counter to track the state of the optimization. BeginRenderOptimize increments this counter and EndRenderOptimize decrements it, therefore the optimization is only performed when needed and any number of BeginRenderOptimize and EndRenderOptimize can be chained together without affecting the document.
This internal data will automatically be freed when the document is disposed, regardless of the value of the counter.
To determine if the document has optimized rendering data, use SvgDocument.IsRenderOptimized.
|Working with SVG|
|SVG Size, Bounds and Flat|
Medical Web Viewer .NET