Color Searching Help

Discussion in 'Programming General' started by pkwithpink, Mar 6, 2010.

Color Searching Help
  1. Unread #1 - Mar 6, 2010 at 6:13 PM
  2. pkwithpink
    Joined:
    Nov 14, 2008
    Posts:
    770
    Referrals:
    0
    Sythe Gold:
    0

    pkwithpink Apprentice
    Banned

    Color Searching Help

    Hi I need help on how to search for a certain RGB color on screen and getting the coordinates of that color. Any help would be appreciated.
     
  3. Unread #2 - Mar 10, 2010 at 7:00 PM
  4. SuF
    Joined:
    Jan 21, 2007
    Posts:
    14,212
    Referrals:
    28
    Sythe Gold:
    1,234
    Discord Unique ID:
    203283096668340224
    <3 n4n0 Two Factor Authentication User Community Participant Spam Forum Participant Sythe's 10th Anniversary

    SuF Legend
    Pirate Retired Global Moderator

    Color Searching Help

    One option is to use: http://java.sun.com/j2se/1.4.2/docs/api/java/awt/Robot.html

    Create a screen capture and work off of that. You just need to loop through all the pixels and such. The main issue you face is that it takes a long ass time and making it function well is quite hard. You need to be able to limit the search area so that it can find the color in a reasonable amount of time.
     
  5. Unread #3 - Apr 11, 2010 at 7:19 AM
  6. Avalon
    Joined:
    Apr 11, 2010
    Posts:
    2
    Referrals:
    0
    Sythe Gold:
    0

    Avalon Newcomer

    Color Searching Help

    This is a primitive version of the current function I've got within a project. Latter abilities could include searching for a point with a specified tolerance etc. It also doesn't include the necessary error-catching that is really required in a complete application, so you'd best add that in if you're going to use it.

    Note: This version also searches in a 'box' like format, I do have a spiral searching version which your welcome to request if you require it.

    It utilises a BufferedImage named currentArea which is repeatedly updated through a thread. The currentArea contains the image-data of a portion of the screen which is selected by the user and retrieved using the java.awt.Robot class as specified above. (Or the entire screen if nothing is selected).

    The function works by utilising the ability to request all the RGB-values of a BufferedImage into an array, this allows for far quicker searching for the specified colour than repeated calls to java.awt.Robot's individual pixel-request function.

    Code:
    /**
     * @param colour The colour to search for in the image.
     * @param area The area to search for the colour, a portion of the stored currentArea.
     * @return Returns the point in reference to the stored currentArea image if found, or 
     *              (-1,-1) if not found.
     */
    public static Point FindColour(Color colour, Rectangle area) {
            int[] rgb = new int[area.width*area.height];
            currentArea.getRGB(area.x, area.y, area.width, area.height, rgb, 0, area.width);
    
            Point found = new Point(-1,-1);
    
            int searchColour = colour.getRGB();
    
            for(int i = 0; i < rgb.length; i++) {
                if(rgb[i] == searchColour) {
                    int y = i / currentArea.getWidth();
                    int x = i - (y*currentArea.getWidth());
    
                    found = new Point(x + area.x,y + area.y);
    
                    return found;
                }
            }
    
            return new Point(-1,-1);
    }
    
     
< Hide/Change IP + Evade Ban Program | I be making a RSC bot >

Users viewing this thread
1 guest


 
 
Adblock breaks this site