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 & HelpSyntax Questions › img.copy() and PImage array
Page Index Toggle Pages: 1
img.copy() and PImage array (Read 1863 times)
img.copy() and PImage array
Mar 8th, 2007, 11:52pm
 
Hi,

I'm having difficulties figuring out why the following piece of code doesn't do what I want it to do.

I have a list of images 'face[]', and mouse input determins which of those images to draw. When the 'curFace' changes I want to copy a section of 'face[curFace]' to another image, 'mouthImg', which for reasons of testing is also drawn - half size - in the lower right of the scene.

The problem is that 'mouthImg' doesn't update each time the curFace changes. Only in the first loop the copy is succesful and for the rest of the time 'mouthImg' stays the same.

I feel I am missing some obvious error in the code, so I hope someone can help see clearer.. or teach me things I did not know about copy();..

thanks

/prinds

link to example applet
http://prinds.com/img_copy_test

Code:

PImage[] face;
int numFaces = 15;

PImage mouthImg = new PImage(225, 75);
int curFace = 0;
int lastFace = -1;

void setup(){
size(320,240);
face = new PImage[numFaces];
for(int i=0; i<numFaces; i++ ){
face[i] = loadImage("face/smile" + nf(i+1,4) + ".gif");
}
}
void draw(){
curFace = 15*mouseX/width;

if(curFace!=lastFace){ //if curFace has changed, copy the mouth of the new face into mouthImg
mouthImg.copy(face[curFace], 50,150, 225,75, 0,0, 225,75);
lastFace=curFace;
}

image(face[curFace],0,0,width,height);
image(mouthImg, 200,200, 225/2,75/2);
noFill();
stroke(255,0,0);
rect( 200,200, 225/2,75/2);
}
Re: img.copy() and PImage array
Reply #1 - Mar 13th, 2007, 5:24pm
 
Hello again,

Found a solution (workaround)..

Calling updatePixels() after the copy() fixes the problem..

Exactly why it is like that I don't know. I noticed that the numbers in pixels[] are changed after the copy (before calling updatePixels()).. Calling updatePixels() doesn't change the actual pixel array, but somehow the image() function now knows where to find the right data..

I someone could explain it, it would sure be nice.

(see the solution at work..http://prinds.com/img_copy_test/)

/prinds
Re: img.copy() and PImage array
Reply #2 - Mar 14th, 2007, 12:06am
 
updatePixels() flags the image as having been modified. i've just updated the reference to explain this more clearly.

copy() shouldn't require updatePixels(), that'll get ironed out in a future beta release.
Re: img.copy() and PImage array
Reply #3 - Nov 21st, 2007, 5:51pm
 
now fixed in rev 0135.
http://dev.processing.org/bugs/show_bug.cgi?id=681
Page Index Toggle Pages: 1