• Post Reply Bookmark Topic Watch Topic
  • New Topic

"Coordinate out of bounds" error when manipulating pixels  RSS feed

 
Pierre Bungle
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good morning/day/evening everyone!

I joined Java Ranch a few years ago, but took an extended break from programming (3 years, in fact... save for some MIPS, which might get a few chuckles) and I'm back at square one. I'm getting back into it, but hit a snag today while trying to manipulate pixels on a JPEG. Essentially, I'm just noodling around with a program that'll do various operations on an image of my choice, and I'm getting the following error when trying to invert an image's colours: "ArrayOutOfBoundsException: Coordinate Out Of Bounds!"

I've spent all day trying to fix this, and am getting nowhere. Spent a few hours on google, to no avail. Java has me by the balls.

This might be relevant: I'm using a GUI (JFrame and JPanel) with a few buttons to load the image, save it, etc. The image is loaded in the CENTRE region of the frame's BorderLayout. Would that affect the image's starting coordinate at all?

Here's my code for the colour inverting method:



Any help would be much appreciated!
 
Greg Charles
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you're reversing height and width. The setRGB() method takes an X parameter, then a Y parameter. Your i iterates through the Y axis (height) of your image and the j through the X.



Now there's a British speller with a stubborn streak!
 
Pierre Bungle
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That worked a treat - thank you very much!

Now there's a British speller with a stubborn streak!


...they'd burn me at the stake over here if I started spelling it 'color' in everyday life ;)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!