We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi, Im executing this code and find this error: "size cannot be used here"
PImage img;
PImage picture;
Integer[] palette;
void setup(){
img = loadImage("palette.jpg");
palette = getPalette(img);
picture = loadImage("picture.jpg");
size(picture.width,picture.height);
background(255);
}
void draw(){
colour(picture, palette);
noLoop();
}
Answers
size is first in setup and can't contain calculations (ie picture.width or height).
look into settings() in the reference.
To understand more, read both of these pages carefully:
Ive done this, and the message is the same
You read up on using
settings()
, but still aren't usingsettings()
? Are you sure you read about it?Ive tried this, but it displays a message saying that the size cannot be calculated in the code
https://Forum.Processing.org/two/discussion/16705/null-pointer-exception-when-loading-image-in-settings-p3-1-1#Item_1
According to the PS3 documentation, the parameters for the
size()
method must only contain integer literals or integer constants. The parameters MUST not be variables or expressions (calculations).The
settings()
method is provided when using other IDEs e.g. Eclipse and is not used in the Processing IDE.You can use the
surface.setSize()
to do what you want like thisThanks, Ill try
@quark -- that's not quite right.
settings()
is normally not needed in Processing 3 PDE, but it works just fine in PDE, and it allows variables insize()
(assetup()
does not.)The example sketch from the settings documentation runs just fine in PDE with a dynamic size:
I am only quoting the PS3 documentation, so don't shoot the messenger :)