←Select platform

Rasterize Method

Renders this SvgDocument to the surface of a LEADTOOLS Leadtools.RasterImage object.
public void Rasterize( 
   RasterImage image, 
   SvgRenderOptions options 
- (BOOL)rasterizeToImage:(LTRasterImage *)image options:(nullable LTSvgRenderOptions *)options error:(NSError **)error; 
public void rasterize(RasterImage image, SvgRenderOptions options) 
void Rasterize(  
   RasterImage^ image, 
   SvgRenderOptions^ options 
def Rasterize(self,image,options): 


The target image. This must be a valid Leadtools.RasterImage object that is allocated and ready to use. Cannot be null.

Options to use during rendering. Can be null.


For more information, refer to SVG Rendering.

Use Render to render this SvgDocument to an output engine.

This method will throw an exception if this document is not flat (the value of IsFlat is false) or if it does not have valid physical (pixel) bounds (the value of Bounds.IsValid is false). image must be previously allocated prior to calling this method. The rendering options passed will determine the position, size and any other transformations 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 entire image area.

If the value of  options is null, then the following default options will be used:

Member Value

The current physical bounds of document (Bounds.Bounds)


Empty rectangle for rendering the document


Identity Leadtools.LeadMatrix




White color


This example will create a raster image then render the pages of a PDF file into the surface of the image before saving it as a PNG file.

using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
using Leadtools.Document.Writer; 
private static void SvgDocumentRasterizeExample() 
   // The source PDF file 
   var sourceFile = $@"{LEAD_VARS.ImagesDir}\Leadtools.pdf"; 
   using (var rasterCodecs = new RasterCodecs()) 
      // Use 300 DPI when loading document images 
      rasterCodecs.Options.RasterizeDocument.Load.Resolution = 300; 
      // Get the size and number of pages in the document 
      int pagePixelWidth; 
      int pagePixelHeight; 
      int pageCount; 
      using (var codecsImageInfo = rasterCodecs.GetInformation(sourceFile, true)) 
         pagePixelWidth = codecsImageInfo.Width; 
         pagePixelHeight = codecsImageInfo.Height; 
         pageCount = codecsImageInfo.TotalPages; 
      // Create a raster image that will contain all the pages as a long stripe. We want to restrict this image size to 200 pixels wide to save memory 
      var imageWidth = 200; 
      var factor = (double)imageWidth / pagePixelWidth; 
      var imageHeight = (int)(factor * pagePixelHeight * pageCount + 0.5); 
      // Create the raster image 
      using (var rasterImage = RasterImage.Create(imageWidth, imageHeight, 32, 96, RasterColor.FromKnownColor(RasterKnownColor.Transparent))) 
         var renderOptions = new SvgRenderOptions(); 
         renderOptions.BackgroundColor = RasterColor.FromKnownColor(RasterKnownColor.Transparent); 
         renderOptions.ClipBounds = LeadRectD.Empty; 
         renderOptions.UseBackgroundColor = false; 
         for (var pageNumber = 1; pageNumber <= pageCount; pageNumber++) 
            // Load this page as SVG 
            using (var svg = rasterCodecs.LoadSvg(sourceFile, pageNumber, null) as SvgDocument) 
               // Flat it 
               if (!svg.IsFlat) 
               if (!svg.Bounds.IsValid) 
               // Set the background bounds 
               renderOptions.Bounds = svg.Bounds.Bounds; 
               // Transform is for destination, translate to our location and scale by our factor 
               var transform = LeadMatrix.Identity; 
               transform.Translate(0, (pageNumber - 1) * pagePixelHeight); 
               transform.Scale(factor, factor); 
               renderOptions.Transform = transform; 
               // Render this SVG to the raster image surface at the specified location and size 
               svg.Rasterize(rasterImage, renderOptions); 
         // Finally, save the raster image as PNG to disk 
         var targetFile = $@"{LEAD_VARS.ImagesDir}\Leadtools_pages_stripe.png"; 
         rasterCodecs.Save(rasterImage, targetFile, RasterImageFormat.Png, 0); 
static class LEAD_VARS 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 

Target Platforms

Help Version 22.0.2023.4.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Svg Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.