Why this code not working

PImage img;

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

void draw() {
  // Since we are going to access the image's pixels too  
  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);          
1 Like

Hey There!

Currently not at the pc but can you use loadPixels with the img like that ?


what happens and what do you want it to happen instead?

E.g. you don’t change r,g,b so nothing happens of course. Do you mean this?

Why that error coming…,…,

check the image name …

does the file exist in the data folder ?

is it JPG or jpg?