addFromCanvas Method

Summary

Adds a new item from an HTML5 Canvas Element.

Syntax

JavaScript Syntax
ImageViewerItems.prototype.addFromCanvas = function(canvas, resolution) 
TypeScript Syntax
addFromCanvas(canvas: HTMLCanvasElement, resolution: LeadSizeD): ImageViewerItem; 

Parameters

canvas

Source HTML5 Canvas Element.

resolution

The resolution to use for the image in dots/inch (DPI). A value of 0,0 or Empty means to use the default image resolution of 96 pixels.

Return Value

The newly created item, if successful.

Remarks

This method allows you to quickly add an item from an HTML5 Canvas Element. It is the equivalent of the following code:

var item = new lt.Controls.ImageViewerItem(); 
item.canvas = canvas; 
item.resolution = resolution; // Optional 
imageViewer.items.add(item); 

AddFromElement can be used as a shortcut for AddFromCanvas or AddFromImage. Passing a valid HTML5 Canvas Element to AddFromElement will create an ImageViewerItem with the Canvas property set, just as it does with AddFromCanvas. Similarly, passing a valid HTML Image Element to AddFromElement will create an ImageViewerItem with the Image property set, just as it does with AddFromImage. The item can have a value in only one of Image, Element or Canvas. Setting one value will automatically delete the values of the others.

To add the ImageViewerItem at a specific location, see InsertFromCanvas or InsertFromElement. To create an item without adding it to any ImageViewer, refer to CreateFromCanvas or CreateFromElement.

If canvas is null, then an empty item is added.

Example

JavaScript Example
var canvas = document.getElementById("myCanvas"); 
var context = canvas.getContext("2d"); 
context.fillStyle = "rgba(0, 0, 255, .5)"; 
context.fillRect(25, 25, 125, 125); 
 
this._imageViewer.items.addFromCanvas(canvas, lt.LeadSizeD.create(96, 96)); 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Controls Assembly