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 › setting pixels in PImage doesn always work
Page Index Toggle Pages: 1
setting pixels in PImage doesn always work (Read 539 times)
setting pixels in PImage doesn always work
Jun 6th, 2007, 11:38am
 
hello, i am defining the pixels in an PImage like this:

for (int y=0;y<pi.height;y++) {
for (int x=0;x<flower.pi.width;x++) {
  int color = getSomeColor();
  //flower.pi.set(x, y, color);
  flower.pi.pixels[y*flower.pi.width+x] = color;
}
}

unfortunately this doesnt always work. in about 30% of the cases the images is only set halfway down. and the lower part is missing.

as you can see, i tried both, setting the pixels with the set() function and writing directly into the pixels array.
Re: setting pixels in PImage doesn always work
Reply #1 - Jun 6th, 2007, 3:12pm
 
http://processing.org/reference/pixels.html

"Before accessing this array, the data must loaded with the loadPixels() functions. After the array data has been modified, the updatePixels() function must be loaded to update the changes."

on the other hand, if you're getting half-complete images, you might be messing with the image data outside of draw(), causing an inconsistency.
Page Index Toggle Pages: 1