How to add images?

Hey, i’m only a few moths in but can’t figure out how to load images. All tutorials I see on this are either from a different processing like 3, or I can’t understand.
They have a bunch of folders to put it into, and I just get confused. And tips?

Hello @WillyGrz,

See the section Loading and displaying data :

Be sure to check out related references as well!

:)

when you are in processing, hit ctrl-k to open your folder.

Here you can place your images. Name it shells.jpg (place it in the folder or create a new folder data and place it there).

then you can say:

size(400,400);
PImage img;
img = loadImage("shells.jpg");
image(img, 0, 0);

When you have a program with setup() and draw() you want:

PImage img; // global scope 

void setup() {
  size(400,400);
  img = loadImage("shells.jpg"); // load 
}

void draw() {
  image(img, 0, 0); // use 
}

this means, load once, use often which is much more efficient than to load in draw().


When you have images in different folders you need to give the full path.


final String pathImg = "D:\\texts\\img.jpg";  // path 

PImage img; // global scope

//-------------------------------------------------------

void setup() {
  size(1400, 800);
  img = loadImage(pathImg); // load
}

void draw() {
  image(img, 0, 0); // use
}

you can also have a list / array of images