Jsui loading image files

Spencer_00's icon

Hi,
how does one load image files into a jsui object? Could someone give me a coding example? I found some info here: https://cycling74.com/docs/max5/vignettes/js/jsimageobject.html

Sorry if this seems like a really simple question but I just can't seem to get it to work.

thanks,

Jan M's icon

This is how it works:

// define your drawing context (canvas) as 2d
sketch.default2d();

function draw(filename) {
    // a) contsructing the new image object with the filename
    var img = new Image(filename);

    // b) optionally: scale the image to a certain size
    img.scale(100,75);

    // c) copy the pixels from the object to the drawing context
    sketch.copypixels(img);

    // d)refresh the display of jsui
    refresh();
}

send the message [draw filename] to the jsui and the image will appear.

j.

Jan M's icon

By the way - jsui uses JavaScript not Java (just because the thread is in the Java forum). Similar name very different things.... ;)

Emmanuel Jourdan's icon

moved to JavaScript forum...