Skip to main content
Version: 9.0.2

canvas.drawImage

canvas.drawImage(name, attrs)

Draw an image within the canvas directed by the user-specified properties.

Parameters

ParameterTypeDescription
name stringThe project-relative name of the image, the same as used in the image render extension.
attrs objectAn object of variables containing information about how to draw the image. See Draw Image Options below.

Draw Image Options

KeyTypeDescription
x numberThe x position of the upper left corner of the text (default: 0).
y numberThe y position of the upper left corner of the text (default: 0).
w numberThe width to scale the image to (default: natural width).
h numberThe height to scale the image to (default: natural height).
rotation numberThe angle of rotation in degrees (default: 0). This rotation point is around the upper left corner of the image.
halign stringThe horizontal anchor, sb.LEFT, sb.CENTER, or sb.RIGHT (default: sb.LEFT).
valign stringThe vertical anchor, sb.TOP, sb.CENTER, or sb.BOTTOM (default: sb.TOP).

Example

// Draw an image scaled to the canvas size
function drawImage(name) {
var canvas = sb.getCanvas(name);
var attrs = {w : canvas.width, h : canvas.height};
canvas.drawImage("images/logo.png", attrs);
}