burnToRect Method

Summary

Burns the annotation objects in Container to the destination context and destination rectangle.

Syntax
TypeScript
JavaScript
AnnRenderingEngine.prototype.burnToRect = function( 
   destinationRect 
) 
burnToRect( 
   destinationRect: LeadRectD 
): void; 

Parameters

destinationRect

The destination rectangle in container coordinates.

Remarks

All visible objects in this container will be drawn into the current context.

This method uses the resolution (DPI) values stored in the container. Use this method when burning the container objects into the context of the image currently being used in the automation.

To burn a container into a context while specifying new resolution (DPI) values, use BurnToRectWithDpi.

Example

This example will create a container, adds a couple of objects and then burn it to a canvas

TypeScript
JavaScript
// Get the container 
var container = this._automation.get_container(); 
 
var inch = 720.0; 
 
// Add a red line object, from 1in 1in to 2in 2in 
var lineObj = new lt.Annotations.Engine.AnnPolylineObject(); 
lineObj.get_points().add(lt.LeadPointD.create(1 * inch, 1 * inch)); 
lineObj.get_points().add(lt.LeadPointD.create(2 * inch, 2 * inch)); 
lineObj.set_stroke(lt.Annotations.Engine.AnnStroke.create(lt.Annotations.Engine.AnnSolidColorBrush.create("red"), lt.LeadLengthD.create(1))); 
container.get_children().add(lineObj); 
 
// Add a blue on yellow rectangle from 3in 3in to 4in 4in 
var rectObj = new lt.Annotations.Engine.AnnRectangleObject(); 
rectObj.set_rect(lt.LeadRectD.create(3 * inch, 3 * inch, 1 * inch, 1 * inch)); 
rectObj.set_stroke(lt.Annotations.Engine.AnnStroke.create(lt.Annotations.Engine.AnnSolidColorBrush.create("blue"), lt.LeadLengthD.create(1))); 
rectObj.set_fill(lt.Annotations.Engine.AnnSolidColorBrush.create("yellow")); 
container.get_children().add(rectObj); 
 
// Add canvas element to the document 
var width = 400; 
var height = 400; 
var canvas = document.createElement("canvas"); 
canvas.style.width = width + "px"; 
canvas.style.height = height + "px"; 
canvas.style.background = "white" 
canvas.style.border = "1px solid"; 
document.body.appendChild(canvas); 
 
// Get the destination rectangle in container coordinates 
// The canvas DPI is 96, and the units are 1/720 of an inch 
// So, sizeInUnits = (sizeInPixels / dpi) = size in inches * 720 = size in container units 
// Or, we can use the annotations mapper, like this 
var mapper = lt.Annotations.Engine.AnnContainerMapper.createDefault(); 
var rc = lt.LeadRectD.create(0, 0, width, height); 
rc = mapper.rectToContainerCoordinates(rc); 
 
// Burn the annotations on this canvas 
 
// Get its context 
var context = canvas.getContext("2d"); 
 
// Create a new rendering engine for burning 
var renderingEngine = new lt.Annotations.Rendering.AnnHtml5RenderingEngine(); 
// Clone the resouces and renderers from current rendering engine to the burn rendering engine 
renderingEngine.resources = this._automation.manager.resources; 
renderingEngine.renderers = this._automation.manager.renderingEngine.renderers; 
    
// Now attach the burn rendering engine with container and context 
renderingEngine.attach(container, context); 
 
// Burn it 
renderingEngine.burnToRect(rc); 
 
// De-Attach both container and context 
renderingEngine.detach(); 
 
// Invalidate 
this._automation.invalidate(lt.LeadRectD.get_empty()); 
// Get the container 
const container: lt.Annotations.Engine.AnnContainer = this._automation.container; 
 
const inch: number = 720.0; 
 
// Add a red line object, from 1in 1in to 2in 2in 
const lineObj: lt.Annotations.Engine.AnnPolylineObject = new lt.Annotations.Engine.AnnPolylineObject(); 
lineObj.points.add(lt.LeadPointD.create(1 * inch, 1 * inch)); 
lineObj.points.add(lt.LeadPointD.create(2 * inch, 2 * inch)); 
lineObj.stroke = lt.Annotations.Engine.AnnStroke.create(lt.Annotations.Engine.AnnSolidColorBrush.create("red"), lt.LeadLengthD.create(1)); 
container.children.add(lineObj); 
 
// Add a blue on yellow rectangle from 3in 3in to 4in 4in 
const rectObj: lt.Annotations.Engine.AnnRectangleObject = new lt.Annotations.Engine.AnnRectangleObject(); 
rectObj.rect = lt.LeadRectD.create(3 * inch, 3 * inch, 1 * inch, 1 * inch); 
rectObj.stroke = lt.Annotations.Engine.AnnStroke.create(lt.Annotations.Engine.AnnSolidColorBrush.create("blue"), lt.LeadLengthD.create(1)); 
rectObj.fill = lt.Annotations.Engine.AnnSolidColorBrush.create("yellow"); 
container.children.add(rectObj); 
 
// Add canvas element to the document 
const width: number = 400; 
const height: number = 400; 
const canvas = document.createElement("canvas"); 
canvas.style.width = width + "px"; 
canvas.style.height = height + "px"; 
canvas.style.background = "white" 
canvas.style.border = "1px solid"; 
document.body.appendChild(canvas); 
 
// Get the destination rectangle in container coordinates 
// The canvas DPI is 96, and the units are 1/720 of an inch 
// So, sizeInUnits = (sizeInPixels / dpi) = size in inches * 720 = size in container units 
// Or, we can use the annotations mapper, like this 
const mapper: lt.Annotations.Engine.AnnContainerMapper = lt.Annotations.Engine.AnnContainerMapper.createDefault(); 
let rc = lt.LeadRectD.create(0, 0, width, height); 
rc = mapper.rectToContainerCoordinates(rc); 
 
// Burn the annotations on this canvas 
 
// Get its context 
const context: CanvasRenderingContext2D = canvas.getContext("2d"); 
 
// Create a new rendering engine for burning 
const renderingEngine: lt.Annotations.Rendering.AnnHtml5RenderingEngine = new lt.Annotations.Rendering.AnnHtml5RenderingEngine(); 
// Clone the resouces and renderers from current rendering engine to the burn rendering engine 
renderingEngine.resources = this._automation.manager.resources; 
renderingEngine.renderers = this._automation.manager.renderingEngine.renderers; 
 
// Now attach the burn rendering engine with container and context 
renderingEngine.attach(container, context); 
 
// Burn it 
renderingEngine.burnToRect(rc); 
 
// De-Attach both container and context 
renderingEngine.detach(); 
 
// Invalidate 
this._automation.invalidate(lt.LeadRectD.empty); 

Requirements

Target Platforms

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

Leadtools.Annotations.Engine Assembly