ImageDrawingArea.java 文件源码

java
阅读 27 收藏 0 点赞 0 评论 0

项目:jhack 作者:
/**
 * Returns the Color of point x, y on the image. Uses
 * <code>PixelGrabber</code> to get the exact color.
 * 
 * @param x Coordinate on the image.
 * @param y Coordinate on the image.
 * @return The Color of the specified point.
 */
public Color getPointColor(int x, int y)
{
    // return new Color(((BufferedImage) img).getRGB(x, y));

    int w = 1, h = 1;
    int[] pixels = new int[w * h];
    PixelGrabber pg = new PixelGrabber(img, x, y, w, h, pixels, 0, w);
    try
    {
        pg.grabPixels();
    }
    catch (InterruptedException e)
    {
        System.err.println("interrupted waiting for pixels!");
        return null;
    }
    int alpha, blue, red, green;

    alpha = (pixels[0] >> 24) & 0xff;
    red = (pixels[0] >> 16) & 0xff;
    green = (pixels[0] >> 8) & 0xff;
    blue = (pixels[0]) & 0xff;

    return new Color(red, green, blue, alpha);
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号