Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

size() function not working in Processing 3.0

I am trying to set size of the window in Processing 3.0 by passing the parameters from the image width and height. However, Processing is throwing an error and asking to check the Reference section which isn't helpful. Code is below.

PImage img;
...

void setup(){
  img = loadImage("XYZ.JPG");
  float w = img.width;
  float h = img.height;
  size(int(w), int(h));
  image(img, 0, 0);
}

and error below:

size() function cannot be used here
like image 678
cndata Avatar asked Oct 25 '25 00:10

cndata


1 Answers

If you're using the size() function from the setup() function, then it has to be the first function you call, and you can't pass variables into it.

If you really need to pass variables into the size() function, then use the settings() function instead of setup().

PImage img;

void settings(){
  img = loadImage("XYZ.JPG");
  float w = img.width;
  float h = img.height;
  size(int(w), int(h));
}

void setup(){
  image(img, 0, 0);
}
like image 130
Kevin Workman Avatar answered Oct 26 '25 15:10

Kevin Workman