We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › height and width change after calling draw()
Page Index Toggle Pages: 1
height and width change after calling draw() (Read 702 times)
height and width change after calling draw()
May 14th, 2006, 2:27pm
 
First of all I have to say, I'm a total newbie to Processing. The problem iI desribe might result from this.

Basically, I want to load an image and filter it. For debugging I first of all just copied the pixels-array of the image to the pixels-array of the display. Here is the code:

PImage face;
int factor = 10;

void setup() {
 int cWidth;
 int cHeight;
   
 face = loadImage("sw3.jpg");
 cWidth = face.width;
 cHeight = face.height;
 
 size(cWidth, cHeight);
 println("setup:height "+ height+" width "+width);
 noLoop();
}

void draw() {
 loadPixels();
 
 println("draw:height "+ height+" width "+width);
 println("draw:face.height "+ face.height+" face.width "+face.width);
 for( int i=0; i<face.height*face.width; i++ ){
   pixels[i] = face.pixels[i];  
 }
 updatePixels();

}

I used the size of the image to initiate the window size. This should stay the same while this program is running. But it is not! The println commands in the setup() and draw() function give the following output:

setup:height 456 width 606
draw:height 456 width 606
draw:face.height 456 face.width 606
draw:height 461 width 608
draw:face.height 456 face.width 606

So, after the second call of draw() the height changes from 456 to 461. Why is that happening?
Re: height and width change after calling draw()
Reply #1 - May 14th, 2006, 5:53pm
 
There is a topic on processinghacks about dynamic window size.

Size needs to be the first command you mention at the beginning of setup(). That's just unfortunately the way it works because size() is a special method. Furthermore, there should be no second call of draw(), you've specified noLoop(): the code in draw() will only be executed once.

Most of your operations on the image you are loading can be done off screen. I put an example below of how this can be done.
Code:

PImage pimage;

void setup() {
size(400, 400);
smooth();
for(int i = 0; i < width; i += 6){
ellipse(i, i, i, i);
}
loadPixels();
pimage = new PImage(width, height);
//the next method copies the screen into pimage
pimage.copy(g, 0, 0, width, height, 0, 0, pimage.width, pimage.height);
}

void draw() {
image(pimage, 0, 0);
}

void mousePressed(){
for(int i = 0; i < pimage.pixels.length; i++){
pimage.pixels[i] = color(255 - red(pimage.pixels[i]));
}
pimage.updatePixels();
}
Re: height and width change after calling draw()
Reply #2 - May 14th, 2006, 6:18pm
 
Thank you for the reply!

But the problem is still there! No matter when I call size() it will change after the first call of draw().
See println-output:
Code:

setup:height 456 width 606
draw:height 456 width 606
draw:face.height 456 face.width 606
draw:height 461 width 608
draw:face.height 456 face.width 606


And yes, it is strange that draw() is called twice. It shouldn't do that since there is the noLoop() command.

Here is the slim code again that produced the output posted above
Code:

PImage face;

void setup() {
size(606,456);

face = loadImage("sw2.jpg");
println("setup:height "+ height+" width "+width);

noLoop();
}

void draw() {
image( face, 0, 0);

println("draw:height "+ height+" width "+width);
println("draw:face.height "+ face.height+" face.width "+face.width);

}
Re: height and width change after calling draw()
Reply #3 - May 14th, 2006, 8:16pm
 
I've just tried your code with an .jpg of my own and I can't reproduce your error, draw-size didn't change. I didn't get a double printout either. Have you tried other images to see if the error is the same? I used Processing 114 on a PC.
Re: height and width change after calling draw()
Reply #4 - May 14th, 2006, 8:46pm
 
I actually used 115 before and switched to 114. Each time the same error ocurred. I also tried another jpg. Same problem!

I use a PC and Linux.

Really strange! Maybe I should just restart my machine?
Re: height and width change after calling draw()
Reply #5 - May 15th, 2006, 2:27am
 
seems to be a linux bug, you're the second to report it... not sure why it's trying to keep resizing the frame like that:
http://dev.processing.org/bugs/show_bug.cgi?id=341
Re: height and width change after calling draw()
Reply #6 - May 15th, 2006, 8:24am
 
That's a bit unfortunate! Is it worth to report it as a bug?
Re: height and width change after calling draw()
Reply #7 - May 15th, 2006, 10:27am
 
i think the link in bens post is already a bug-report on that ... anyway, he is now aware of it.
Page Index Toggle Pages: 1