#include "l_bitmap.h"

L_LTSVG_API L_INT L_SvgRasterizeDocument(bitmapHandle, flatDocHandle, options)

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


BITMAPHANDLE* bitmapHandle

The target image. This must be a valid BITMAPHANDLE that is allocated and ready to use. Cannot be NULL.

const L_SvgNodeHandle flatDocHandle

Handle to the SVG document to be rendered.

const L_SvgRenderOptions* options

Options to use during rendering. Can be NULL.


Value Meaning
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:

Member Value
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


Win32, x64, Linux.

See Also




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); 
   // 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); 
   renderOptions.Bounds = srcBounds; 
   // 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 21.0.2021.4.7
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.