Load and Display Image / 画像の読み込みと表示

画像は、実際のサイズまたはその他のサイズで画面に読み込んで表示できます。

loadImage image
Image

View Source Code

/*
 * @name Load and Display Image
 * @arialabel An astronaut on a planet with the same image in a smaller size in the bottom left quarter
 * @description Images can be loaded and displayed to the screen at their
 * actual size or any other size.
 * <p><em><span class="small"> To run this example locally, you will need an 
 * image file, and a running <a href="https://github.com/processing/p5.js/wiki/Local-server">
 * local server</a>.</span></em></p>

 */
let img; // Declare variable 'img'.

function setup() {
  // createCanvas(720, 400);
  createCanvas(windowWidth, windowHeight);
  // img = loadImage('assets/moonwalk.jpg'); // Load the image
  img = loadImage('../../../../p5js-website-legacy-examples/assets/moonwalk.jpg'); // Load the image
}

function draw() {
  // Displays the image at its actual size at point (0,0)
  image(img, 0, 0);
  // Displays the image at point (0, height/2) at half size
  image(img, 0, height / 2, img.width / 2, img.height / 2);
}

License

Source code is available on GitHub p5.js website legacy.

All examples are licensed under CC BY-NC-SA 4.0.