←Select platform

EndRenderOptimize Method

Clears the rendering optimization data.
public void EndRenderOptimize() 
- (BOOL)endRenderOptimize:(NSError **)error; 
public void endRenderOptimize() 
void EndRenderOptimize();  
def EndRenderOptimize(self): 

For more information, refer to SVG Rendering.

SvgDocument will create internal data structures to speed up rendering. This data can be cached and re-used by using SvgDocument.BeginRenderOptimize and SvgDocument.EndRenderOptimize.

If the 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 Leadtools.Controls.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 can use extra system resources stored in the internal data. Use EndRenderOptimize to free this data manually at any time.

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 be freed automatically when the document is disposed of, regardless of the value of the counter.

To determine whether the document has optimized rendering data, use SvgDocument.IsRenderOptimized.

using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
using Leadtools.Document.Writer; 
public void SvgDocumentRenderExample() 
   // Create a form with a picture box 
   Form form = new Form(); 
   PictureBox pictureBox = new PictureBox(); 
   pictureBox.Dock = DockStyle.Fill; 
   SvgDocument document = null; 
   // Load a page from a document file as SVG 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"); 
   using (var codecs = new RasterCodecs()) 
      // Set 300 as the default value for loading document files 
      codecs.Options.RasterizeDocument.Load.Resolution = 300; 
      document = codecs.LoadSvg(srcFileName, 1, null) as SvgDocument; 
   // Make sure the document is valid for rendering 
   if (!document.IsFlat) 
   if (!document.Bounds.IsValid) 
   // Optimize it for rendering to increase the speed 
   Console.WriteLine("IsRenderOptimized is " + document.IsRenderOptimized); 
   // This is our paint code 
   pictureBox.Paint += (sender, e) => 
      Graphics graphics = e.Graphics; 
      // We will fit and center this SVG document in the client area of the picture box 
      Rectangle dstBounds = pictureBox.ClientRectangle; 
      if (dstBounds.Width < 1 || dstBounds.Height < 1) 
      // Create the transformation matrix 
      LeadMatrix transform = LeadMatrix.Identity; 
      LeadRectD srcBounds = document.Bounds.Bounds; 
      // Calculate the zoom so we can fit 
      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 
      transform.Scale(zoom, zoom); 
      // Center 
      double xOffset = (dstBounds.Width - (zoom * srcBounds.Width)) / 2.0; 
      double yOffset = (dstBounds.Height - (zoom * srcBounds.Height)) / 2.0; 
      transform.Translate(xOffset, yOffset); 
      // Now setup the rendering options 
      SvgRenderOptions options = new SvgRenderOptions(); 
      // Use our transform 
      options.Transform = transform; 
      // clipping (if any) 
      options.ClipBounds = LeadRectD.Create(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height); 
      // Fill the background with a white color 
      options.UseBackgroundColor = true; 
      options.BackgroundColor = RasterColor.FromKnownColor(RasterKnownColor.White); 
      options.Bounds = srcBounds; 
      // Create a rendering engine 
      using (var engine = RenderingEngineFactory.Create(graphics)) 
         // Render the document 
         document.Render(engine, options); 
   form.SizeChanged += (sender, e) => pictureBox.Invalidate(); 
static class LEAD_VARS 
   public const string ImagesDir = @"C:\LEADTOOLS23\Resources\Images"; 
import java.io.ByteArrayInputStream; 
import java.io.ByteArrayOutputStream; 
import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileOutputStream; 
import java.io.IOException; 
import java.io.ObjectInputStream; 
import java.io.ObjectOutputStream; 
import java.io.PrintStream; 
import java.nio.file.FileVisitOption; 
import java.nio.file.Files; 
import java.nio.file.Path; 
import java.nio.file.Paths; 
import java.util.stream.Stream; 
import org.junit.*; 
import org.junit.runner.JUnitCore; 
import org.junit.runner.Result; 
import org.junit.runner.notification.Failure; 
import static org.junit.Assert.*; 
import leadtools.*; 
import leadtools.codecs.*; 
import leadtools.document.writer.*; 
import leadtools.svg.*; 
public void svgDocumentRenderExample() { 
   // Skipped due to java ui 

Target Platforms

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

Leadtools.Svg Assembly

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