I'm new to Java (and programming in general) and I've been having trouble when trying to work with images. The goal of the program is to "scale down" a picture (scale down the image by a factor of two by merging every 4 pixels into 1 pixel) so I did a for loop inside of a for loop and have managed to assign the average of 4 pixels into 1 pixel. My issue instead comes from the fact that I keep getting an error: Exception in thread "AWT-EventQueue-0" java.lang.IndexOutOfBoundsException: row 0, col 102 is out of bounds! number of rows is 151, number of columns is 101 So- and I run out of t
I still run out of bounds on half of my pictures but the other half work fine?
The fact that you're working with 2x2 grids of pixels suggests that you're going through the pixels in increments of two and not checking to see if the current position plus two is still in range. You'll probably find that the pictures that your code doesn't work on all have an odd number of columns, and the pictures that do work have an even number of columns. You probably have the same problem with the rows.
Join our real-time social learning platform and learn together with your friends!