Name

imageMode()

Description

Modifies the location from which images are drawn by changing the way in which parameters given to image() are interpreted.

The default mode is imageMode(CORNER), which interprets the second and third parameters of image() as the upper-left corner of the image. If two additional parameters are specified, they are used to set the image's width and height.

imageMode(CORNERS) interprets the second and third parameters of image() as the location of one corner, and the fourth and fifth parameters as the opposite corner.

imageMode(CENTER) interprets the second and third parameters of image() as the image's center point. If two additional parameters are specified, they are used to set the image's width and height.

The parameter must be written in ALL CAPS because Processing is a case-sensitive language.

Examples

  • PImage img;
    
    void setup() {
      size(400,400);
      img = loadImage("Toyokawa.jpg");
    }
    
    void draw() {
      imageMode(CORNER);
      image(img, 40, 40, 200, 200);  // Draw image using CORNER mode
    }
    Image output for example 1
  • PImage img;
    
    void setup() {
      size(400,400);
      img = loadImage("Toyokawa.jpg");
    }
    
    void draw() {
      imageMode(CORNERS);
      image(img, 40, 40, 360, 160);  // Draw image using CORNERS mode
    }
    Image output for example 2
  • PImage img;
    
    void setup() {
      size(400,400);
      img = loadImage("Toyokawa.jpg");
    }
    
    void draw() {
      imageMode(CENTER);
      image(img, 200, 200, 320, 320);  // Draw image using CENTER mode
    }
    Image output for example 3

Syntax

  • imageMode(mode)

Parameters

  • mode(int)either CORNER, CORNERS, or CENTER

Return

  • void