canvas.drawImage
canvas.drawImage(name, attrs)
Draw an image within the canvas directed by the user-specified properties.
Parameters
| Parameter | Type | Description |
|---|---|---|
name | string | The project-relative name of the image, the same as used in the image render extension. |
attrs | object | An object of variables containing information about how to draw the image. See Draw Image Options below. |
Draw Image Options
| Key | Type | Description |
|---|---|---|
x | number | The x position of the upper left corner of the text (default: 0). |
y | number | The y position of the upper left corner of the text (default: 0). |
w | number | The width to scale the image to (default: natural width). |
h | number | The height to scale the image to (default: natural height). |
rotation | number | The angle of rotation in degrees (default: 0). This rotation point is around the upper left corner of the image. |
halign | string | The horizontal anchor, sb.LEFT, sb.CENTER, or sb.RIGHT (default: sb.LEFT). |
valign | string | The 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);
}