We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
It seems like once I draw an image to the display window, it's not possible to redraw it with an increased size any more.
I get an ArrayIndexOutOfBoundsException: Coordinate out of bounds! error message.
Decreasing size works, however.
Any hint?
Thanks, Gyula
Test code:
PImage img;
int imgWidth = 66;
void setup() {
size(100, 100);
// Create image
img = createImage(imgWidth, imgWidth, RGB);
img.loadPixels();
for (int i = 0; i < img.pixels.length; i++) {
img.pixels[i] = color(255);
}
img.updatePixels();
// Do not loop draw()
noLoop();
}
void draw() {
background(0);
imageMode(CENTER);
image(img, 50, 50);
}
void keyPressed() {
if (key == CODED) {
if (keyCode == UP)
imgWidth += 10;
else if (keyCode == DOWN)
imgWidth -= 10;
// Constrain imgWidth
imgWidth = max(imgWidth, 6);
println(imgWidth);
img.resize(imgWidth, 0);
// Redraw image
redraw();
}
}
P.S.: My test code looks messed up in the Preview window. Anyway, I'll post this message.
Answers
I'm sorry to see the same ugly code format in the posted message. :( Are the curly braces the culprits or me?
I'm trying to edit it to help out right now. Just place four spaces or a tab before each line of code.
Ok, thanks a lot, REAS.
Well, seems like resize() only works for shrinking.
But resizing w/ image() works in all cases:
P.S: To get those 4 spaces for code display here, in Processing use CTRL+A,
then CTRL+] to increase indentation as many times you need to get at least 4.
And finally CTRL+C there and CTRL+V here! (*)
It is a bad idea to resize your image several times like this, anyway. The quality will degrade on each operation. That's why
image()
with the wanted size is a better option.resize()
is more to do a one-time operation once you loaded the image, IMHO.@GoToLoop:
I think once I've used image() to display the image, somehow its maximum size gets "freezed". But before the first call of image() for the image, I can freely use resize() even for enlargement (if I'm fool enough to ignore PhiLho's previous post :) ).
How very true! Shouldn't that be emphasized in the Processing reference?
BTW, the reason why I want to resize the image several times is because my image is a "heatplot" or "rasterplot", where I need to zoom in to tiny details if necessary.
Thanks to both of you for the help.