Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

"Coordinate out of bounds" error when manipulating pixels

 
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!
 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • 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 ;)
 
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic