Autodesk Canvas Library Version 1.0
Autodesk Canvas Library

Image Overview

The compatible Image constructor for Browser and Node.js environment. It provides several ways of loading image file, usually it as the input when draw image on Canvas.

Introduced in Version: 1.0.0

2 Examples:

    // Load image from a data url
    var img = new Image();
    img.onerror=function(e) {
        Debug.log("img.onerror: " + e);
    };
    img.onload = function() {
        Debug.log("img.onload");
        callback(img);
    };
    img.src = dataUrl;
    // Load image from a file
    var imageFile = params["image"]; // params have a {Runtime.File} instance
    if (imageFile !== undefined && imageFile !== "") {
        var img = new Image();
        img.loadFromFile(imageFile, function(image){
            if (!image) {
                Plugin.panic("Can't load the image: " + imageFile.name));
            }
        });
    }

Class Member Summary

Class Member Details

• loadFromFile (file, callback) | Asynchronous

Load image from a File.
  • file: File - A File instance
  • callback: Function ( Image ) - A callback function will be called once image loaded in document.

Function ( ) onerror

Fires when image is loaded failed with the error if assigned.

Function ( ) onload

Fires when image is loaded successfully if assigned.

String src

Assign a data url to this property will load the image data