The Java size() function does not work in Processing 3.0

I tried to set the window size by passing parameters from image width and height in Processing 3.0 However, processing is throwing an error and asking to check the reference section, which is not helpful to you The code is as follows

PImage img;
...

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

And errors are as follows:

size() function cannot be used here

Solution

If you are using the size () function in the setup () function, it must be the first function you call, and you cannot pass variables to it

If you really need to pass a variable to the size () function, 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);
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>