Gets the color at the specified point on BufferedImage. - Java 2D Graphics

Java examples for 2D Graphics:BufferedImage Color

Description

Gets the color at the specified point on BufferedImage.

Demo Code


import java.awt.Color;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

public class Main{
    /**//from w  w  w.  ja v a2 s.  com
     * Gets the color at the specified point.
     * 
     * @param p
     *            - The point at which you wish desire a color.
     * @return The color at the point specified.
     */
    public static Color getColor(Point p) {
        BufferedImage b = getScreen();
        return new java.awt.Color(b.getRGB(p.x, p.y));
    }
    /**
     * Gets the color at the specified coordinates.
     * 
     * @param x
     *            The x coordinate of the point at which you desire a color.
     * @param y
     *            The y coordinate of the point at which you desire a color.
     * @return The color at the coordinates specified.
     */
    public static Color getColor(int x, int y) {
        BufferedImage b = getScreen();
        return new java.awt.Color(b.getRGB(x, y));
    }
    /**
     * @return Game Screen as BufferedImage.
     */
    public static BufferedImage getScreen() {
        return Client.getScreen();
    }
}

Related Tutorials