This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
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.
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.