[−][src]Static p5_sys::global::loadImage
pub static loadImage: LoadImageInternalType
Loads an image from a path and creates a p5.Image from it.
The image may not be immediately available for rendering. If you want to ensure that the image is ready before doing anything with it, place the loadImage() call in preload(). You may also supply a callback function to handle the image when it's ready.
The path to the image should be relative to the HTML file that links in your sketch. Loading an image from a URL or other remote location may be blocked due to your browser's built-in security.
You can also pass in a string of a base64 encoded image as an alternative to the file path. Remember to add "data:image/png;base64," in front of the string.
Examples
let img;
function preload() {
img = loadImage('assets/laDefense.jpg');
}
function setup() {
image(img, 0, 0);
}
function setup() {
// here we use a callback to display the image after loading
loadImage('assets/laDefense.jpg', img => {
image(img, 0, 0);
});
}
Parameters
path
Path of the image to be loaded
successCallback?
Function to be called once
the image is loaded. Will be passed the
p5.Image.
failureCallback?
called with event error if
the image fails to load.