This gives an ArrayIndexOutOfBoundsException for -14342875 at line 26. Why?
in
Programming Questions
•
1 year ago
-
PImage rocks;
-
int rockBytes[][];
-
int histogram[];
-
void setup() {
- rocks = loadImage("rocks.jpg");
- rocks.loadPixels();
- histogram = new int[256];
- size(rocks.width*2, rocks.height*2);
- image(rocks, 0, 0);
- rockBytes = new int[rocks.width][rocks.height];
- for (int i = 0; i < rocks.width; i++) {
- for (int j = 0; j < rocks.height; j++) {
rockBytes[i][j] = rocks.get(i, j);
- }
- }
- computeHistogram (rocks);
- }
- void loadPixelArray(PImage anImage){
-
anImage.loadPixels(); //load pixels into pixels[] array
- }
- void computeHistogram(PImage anImage) {
- loadPixelArray(anImage);
- int histMax = 0;
- for (int x = 0; x < anImage.width; x++) {
- for (int y = 0; y < anImage.height; y++ ) {
- int loc = x + y*anImage.width;
- histogram[anImage.pixels[loc]]++;
- }
- }
- for (int i = 0; i < histogram.length; i++) {
- if (histogram[i] > histMax) {
- histMax = histogram[i];
- }
- }
- for (int i = 0; i < histogram.length; i++) {
- histogram[i] = histogram[i]*100/histMax;
- }
-
}
1