ArrayIndexOutOfBoundsException: 168270

Hey guys

I have been trying to manipulate pixels on an image, following the youtube tutorial: https://www.youtube.com/watch?v=j-ZLDEnhT3Q by the Coding Train.

I can’t seem to get it to work. Error code reads… ArrayIndexOutOfBoundsException: 168270

Here is my code:

PImage sunf;

void setup(){
 size (474, 355); 
  sunf = loadImage("sunf.jpg");
}

void draw(){
  image(sunf, 0, 0);
  loadPixels();
  sunf.loadPixels();
  for(int x = 0; x < width; x++){
    for(int y = 0; y < width; y++){
      int loc = x+y*width;
      float r = red(sunf.pixels[loc]);
      float g = green(sunf.pixels[loc]);
      float b = blue(sunf.pixels[loc]);
      pixels[loc] = color(r,g,b*2); 
}
  }
  updatePixels();
}

Any help/advice would be greatly appreciated. Thanks.

J

1 Like

Try instead:

for(int y = 0; y < height; y++){
1 Like

Duh! Thanks TfGuy44, appreciate your help, embarrassed about my incompetence