• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Colour bounds method

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi!

Was wondering if there is a comparable method in the Java API (maybe in Swing) that carries out the same function as this one found in ActionScript.

It's a method which determines a rectangular region that fully encloses all pixels of a specified color within a bitmap image; so if there are two red circles at opposite corners of an image then the rectangular region returned would cover the entire image.

I'm sure there is, but I've spent ages searching and can't seem to find anything.
 
Bartender
Posts: 1849
15
Eclipse IDE Spring VI Editor Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch!

I think you might find good response in the GUI forum... I'll move this there
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not aware that something like this exists, but it isn't that hard to write one yourself using BufferedImage. Use getWidth(), getHeight() and getRGB(int x, int y). In short, you iterate over every pixel, checking if the colour at that pixel matches the desired colour. You keep track of the minimum and maximum x and y values with a match. You can start these values like this:
None of these values fall within the image so if at the end you get that one of these values is still at the initial position you know that the colour did not occur at all in the image.
 
R Jay
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the response.

I have now written the method myself, but I thought there would be a more efficient one lurking somewhere in the API.

It turned out to be a fairly easy algorithm to implement -- at least now I understand it!
 
Rob Spoor
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And that's always a good thing.
 
reply
    Bookmark Topic Watch Topic
  • New Topic