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
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);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With