我做的是区域填充,使用使用鼠标在控件上画一个封闭几何形状,该如何获得控件上任意一点的像素值?如获得我用鼠标所画线条的RGB值。

解决方案 »

  1.   

    用Robot的public Color getPixelColor(int x, int y)方法取鼠标位置当前色Color pixel = new Color(0,0,0);
    Robot robot;
    Point mousepoint;
    int R,G,B;
    MouseInfo mouseinfo;
    robot = new Robot();
    mousepoint = mouseinfo.getPointerInfo().getLocation();
    pixel = robot.getPixelColor(mousepoint.x,mousepoint.y);
    R = pixel.getRed();
    G = pixel.getGreen();
    B = pixel.getBlue();