burnToRectWithDpi Method

Summary

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

Syntax
TypeScript
JavaScript
AnnRenderingEngine.prototype.burnToRectWithDpi = function( 
   destinationRect, 
   sourceDpiX, 
   sourceDpiY, 
   targetDpiX, 
   targetDpiY 
) 
burnToRectWithDpi( 
   destinationRect: LeadRectD, 
   sourceDpiX: number, 
   sourceDpiY: number, 
   targetDpiX: number, 
   targetDpiY: number 
): void; 

Parameters

destinationRect

The destination rectangle in container coordinates.

sourceDpiX

Horizontal source (screen) DPI.

sourceDpiY

Vertical source (screen) DPI.

targetDpiX

Horizontal target (image) DPI.

targetDpiY

Vertical target (image) DPI.

Remarks

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

This method uses the resolution (DPI) values specified and not the values stored in the container. Use this method when burning the container objects into any context.

To burn a container into the context of the image being automated, use Burn.

Example

This example will create a container, adds a couple of objects and then burn it into the viewer

TypeScript
JavaScript
// _viewer is ImageViewer this._automation is working on 
 
// 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); 
 
// To burn the annotations, we need a canvas context and a new rendering engine 
 
// Get the background canvas of the viewer 
var canvas = this._viewer.activeItem.canvas; 
var context = canvas.getContext("2d"); 
 
// Create a new rendering engine for burning 
var renderingEngine = new lt.Annotations.Rendering.AnnHtml5RenderingEngine(); 
// Clone the resources 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); 
 
// Set the resolution 
var dpiX = this._viewer.get_screenDpi().width; 
var dpiY = this._viewer.get_screenDpi().height; 
var xRes = this._viewer.activeItem.get_resolution().width; 
var yRes = this._viewer.activeItem.get_resolution().height; 
 
// Burn it 
renderingEngine.burnToRectWithDpi(lt.LeadRectD.get_empty(), dpiX, dpiY, xRes, yRes); 
 
// De-Attach both container and context 
renderingEngine.detach(); 
 
// Delete the objects we added 
this._automation.selectObjects(container.get_children()); 
this._automation.deleteSelectedObjects(); 
 
// Invalidate to see the burned objects 
this._viewer.invalidate(lt.LeadRectD.get_empty()); 
// _viewer is ImageViewer this._automation is working on 
 
// 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); 
 
// To burn the annotations, we need a canvas context and a new rendering engine 
 
// Get the background canvas of the viewer 
const canvas = this._viewer.activeItem.canvas as HTMLCanvasElement; 
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 resources 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); 
 
// Set the resolution 
const dpiX: number = this._viewer.screenDpi.width; 
const dpiY: number = this._viewer.screenDpi.height; 
const xRes: number = this._viewer.activeItem.resolution.width; 
const yRes: number = this._viewer.activeItem.resolution.height; 
 
// Burn it 
renderingEngine.burnToRectWithDpi(lt.LeadRectD.empty, dpiX, dpiY, xRes, yRes); 
 
// De-Attach both container and context 
renderingEngine.detach(); 
 
// Delete the objects we added 
this._automation.selectObjects(container.children); 
this._automation.deleteSelectedObjects(); 
 
// Invalidate to see the burned objects 
this._viewer.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