Using external image files (PImage, PShape)

You can load bitmap and vector files in processing.

Bitmap
Don’t forget to declare PImage type variables.

PImage img;
 
void setup() {
  size(300, 300);
  img = loadImage("filename.png"); //the file has to be in the same folder 
  noLoop();
}
 
void draw() {
  image(img, 0, 0);
}

It works with alpha too!
Add an alpha channel in photoshop.

Defining position and size:

image(img, 50, 50, 200, 200);

Transformations can be applied as it was a rect shape:

imageMode(CENTER);
 
  pushMatrix();
    translate(150, 150);
    rotate(radians(45));
    image(img, 0, 0, 200, 200);
  popMatrix();

Vector
SVG Image made in Illustrator. Download from here.

PShape s;
 
void setup() {
  size(200, 200);
  //noLoop();
  noStroke();
  smooth();
  background(0);
  shapeMode(CENTER);
}
 
void draw() {
  background(255); 
  s = loadShape("shape.svg");
  shape(s, 100, 100);
  }
Posted in

Post a comment