#include "l_bitmap.h"

L_LTSVG_API L_INT L_SvgRasterizeDocument(bitmapHandle, flatDocHandle, options)

pBITMAPHANDLE* bitmapHandle;

pointer to the target bitmap

const L_SvgNodeHandle flatDocHandle;

SVG document handle

const L_SvgRenderOptions* options;

pointer to options structure

Renders the specified SVG document to the surface of the specified LEADTOOLS BITMAPHANDLE.

Parameter Description
bitmapHandle The target image. This must be a valid BITMAPHANDLE that is allocated and ready to use. Cannot be NULL.
flatDocHandle Handle to the SVG document to be rendered.
options Options to use during rendering. Can be NULL.


SUCCESS The function was successful.
< 1 An error occurred. Refer to Return Codes.


Support for SVG is only available in the Document and Medical Imaging toolkits.

The bitmapHandle must be previously allocated prior to calling this function. The rendering options passed will determine the position, size and any other transformation that will occur. With these options, it is possible to render the SVG document into any destination rectangle on the image or to fill the whole image area.

This function will return an error if the specified SVG document is not flat or if it does not have valid physical (pixel) bounds.

If the options is NULL, then these default options will be used:



Bounds The current physical bounds of document.
ClipBounds Empty rectangle to render the whole document.
Transform Identity.
UseBackgroundColor TRUE
BackgroundColor White color

Required DLLs and Libraries

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.


Win32, x64, Linux.

See Also
Functions: L_SvgRenderDocument, L_SvgBeginRenderOptimizeDocument, L_SvgEndRenderOptimizeDocument, L_SvgIsRenderOptimizedDocument
Topics: Working with SVG
SVG Rendering


This example will render an SVG document to a BITMAPHANDLE.

L_INT SvgRasterizeDocumentExample(L_SvgNodeHandle docHandle, BITMAPHANDLE* bitmap) 
   L_SvgNodeHandle flatDocHandle = docHandle; 
   // If the document is non-flat, flatten it, automatically calculating the size 
   L_BOOL isFlat = TRUE; 
   L_INT nRet = L_SvgIsFlatDocument(docHandle, &isFlat); 
   if (!isFlat) 
      L_SvgFlatDocument(docHandle, &flatDocHandle, NULL); 
   L_SvgBounds bounds; 
   L_SvgGetBounds(flatDocHandle, &bounds, sizeof(L_SvgBounds)); 
   if (!bounds.IsValid) 
      L_SvgCalculateBounds(flatDocHandle, FALSE); 
   // Optimize it for rendering to increase the speed 
   L_BOOL optimized = L_SvgIsRenderOptimizedDocument(flatDocHandle); 
   // This is our paint code 
   // We will fit and center this SVG document in the BITMAPHANDLE's dimensions 
   L_RECTD dstBounds; 
   dstBounds.x = dstBounds.y = 0; 
   dstBounds.width = bitmap->Width; 
   dstBounds.height = bitmap->Height; 
   if (dstBounds.width < 1 || dstBounds.height < 1) 
      return FAILURE; 
   // Create the transformation matrix 
   L_MATRIX transform; 
   L_SvgGetBounds(flatDocHandle, &bounds, sizeof(L_SvgBounds)); 
   L_RECTD srcBounds = bounds.Bounds; 
   // Calculate the zoom so we can fit 
   L_DOUBLE zoom = 1.0; 
   if (dstBounds.width > dstBounds.height) 
      zoom = dstBounds.width / srcBounds.width; 
      if ((zoom * srcBounds.height) > dstBounds.height) 
         zoom = dstBounds.height / srcBounds.height; 
      zoom = dstBounds.height / srcBounds.height; 
      if ((zoom * srcBounds.width) > dstBounds.width) 
         zoom = dstBounds.width / srcBounds.width; 
   // We have the zoom factor, set it in the transform 
   L_Matrix_Scale(&transform, zoom, zoom); 
   // Center 
   L_DOUBLE xOffset = (dstBounds.width - (zoom * srcBounds.width)) / 2.0; 
   L_DOUBLE yOffset = (dstBounds.height - (zoom * srcBounds.height)) / 2.0; 
   L_Matrix_Translate(&transform, xOffset, yOffset); 
   // Now setup the rendering options 
   L_SvgRenderOptions renderOptions = {0}; 
   renderOptions.StructSize = sizeof(L_SvgRenderOptions); 
   // All of the document 
   renderOptions.Bounds = srcBounds; 
   // Use our transform 
   renderOptions.Transform = transform; 
   // no clipping 
   L_RectD_FromLTRB(&renderOptions.ClipBounds, 0, 0, dstBounds.width, dstBounds.height); 
   // Fill the background with a white color 
   renderOptions.UseBackgroundColor = TRUE; 
   renderOptions.BackgroundColor = RGB(255,255,255); 
   // Rasterize the document 
   nRet = L_SvgRasterizeDocument(bitmap, flatDocHandle, &renderOptions); 
   if (nRet != SUCCESS) 
      if (!isFlat) 
      return nRet; 
   if (!optimized) 
      nRet = L_SvgEndRenderOptimizeDocument(flatDocHandle); 
   return nRet; 

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.