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.
IndexSuggestions & BugsWebsite,  Documentation,  Book Bugs › Error in "Images and Pixels" section
Page Index Toggle Pages: 1
Error in "Images and Pixels" section (Read 1020 times)
Error in "Images and Pixels" section
Jan 16th, 2010, 12:01pm
 
In the subsection "Intro To Image Processing", the piece of could:

PImage img;

void setup() {
 size(200, 200);
 img = loadImage("sunflower.jpg");
}

void draw() {
 loadPixels();
 // Since we are going to access the image's pixels too  
 img.loadPixels();
 for (int y = 0; y < height; y++) {
   for (int x = 0; x < width; x++) {
     int loc = x + y*width;
     
     // The functions red(), green(), and blue() pull out the 3 color components from a pixel.
     float r = red(img.pixels[loc]);
     float g = green(img.pixels[loc]);
     float b = blue(img.pixedls[loc];
     
     // Image Processing would go here
     // If we were to change the RGB values, we would do it here, before setting the pixel in the display window.
     
     // Set the display pixel to the image pixel
     pixels[loc] =  color(r,g,b);          
   }
 }
 updatePixels();
}


Should be:

PImage img;

void setup() {
 size(200, 200);
 img = loadImage("sunflower.jpg");
}

void draw() {
 loadPixels();
 // Since we are going to access the image's pixels too  
 img.loadPixels();
 for (int y = 0; y < height; y++) {
   for (int x = 0; x < width; x++) {
     int loc = x + y*width;
     
     // The functions red(), green(), and blue() pull out the 3 color components from a pixel.
     float r = red(img.pixels[loc]);
     float g = green(img.pixels[loc]);
     float b = blue(img.pixels[loc]);
     
     // Image Processing would go here
     // If we were to change the RGB values, we would do it here, before setting the pixel in the display window.
     
     // Set the display pixel to the image pixel
     pixels[loc] =  color(r,g,b);          
   }
 }
 updatePixels();
}
Page Index Toggle Pages: 1