最近做了个屏幕鼠标移动监听与屏幕取色的功能。用到了Invoke.jar这个API。用了一段时间,挺好。今天突然发现丫要收费。不买就用不了这功能了。求Invoke.jar的替代工具。或给思路实现鼠标屏幕取色。谢谢各位。

解决方案 »

  1.   

    标记下,下午做一下。
    不过还得看看 颜色的类api。
      

  2.   

    看了下,api 里面有~~~~~~~~·Robot robot = null;
    try {
    robot = new Robot();
    } catch (AWTException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }int x = 0;
    int y = 0;
    Color color = robot.getPixelColor(x, y);
    这个类还可以实现截屏功能!
      

  3.   

    具体代码
    public class ScreenDemo {

    public static void main(String[] args) {
    Robot robot = null;
    try {
    robot = new Robot();
    } catch (AWTException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    Rectangle screenRect = null;

    screenRect = new Rectangle(new Dimension(800,600));
    screenRect.setLocation(0, 0);

    BufferedImage image = robot.createScreenCapture(screenRect);

    FileOutputStream fos = null;
    try {
    fos = new FileOutputStream(new File("F:\\screen.jpg"));
    } catch (FileNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }


    try {
    ImageIO.write(image, "JPG", fos);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }


    int x = 0;
    int y = 0;
    Color color = robot.getPixelColor(x, y);
    }}
    需要再做下 鼠标拉框的 方法
      

  4.   

    要有鼠标事件必须要有个frame对象啊。
    楼主你要做出来个什么东西?达到什么效果呢?
      

  5.   

    Robot 截的图,没有鼠标位置。
      

  6.   

    实验下这个截屏类,楼主多看看吧public class PrintScreen {

    private JFrame frame;
    private GraphicsEnvironment ge;
    private GraphicsDevice gd;
    private DisplayMode dm;

    private int x1,y1;
    private int x2,y2;

    private boolean b1 = true;


    public void createAndShowUI(){

    ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    gd = ge.getDefaultScreenDevice();
    dm = gd.getDisplayMode();


    int dim_w = 200;
    int dim_h = 200;
    frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    frame.setPreferredSize(new Dimension(dim_w, dim_h));
    Container contentPane = frame.getContentPane();


    JButton b1 = new JButton("截图");

    b1.addMouseListener(new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
    printScreen();
    }
    });
    contentPane.add(b1,BorderLayout.SOUTH);
    //
    int x = dm.getWidth();
    int y = dm.getHeight();
    frame.setLocation(x - dim_w, 0);
    frame.pack();
    frame.setVisible(true);

    }

    private void printScreen(){
    createFrame();
    }

    private void createFrame(){

    JFrame f = new JFrame("选择区域");
    f.setPreferredSize(new Dimension(dm.getWidth(),dm.getHeight()));
    // gd.setFullScreenWindow(f);



    f.addMouseListener(new MouseListener() {

    public void mouseReleased(MouseEvent e) {
    if(b1==true){
    x2 = e.getXOnScreen();
    y2 = e.getYOnScreen();
    b1 = false;
    System.out.println("released " + x2 + " : " + y2);
    }

    }

    public void mousePressed(MouseEvent e) {
    // TODO Auto-generated method stub
    if(b1==true){
    x1 = e.getXOnScreen();
    y1 = e.getYOnScreen();
    System.out.println("pressed " + x1 + " : " + y1);
    }

    }

    public void mouseExited(MouseEvent e) {
    // TODO Auto-generated method stub

    }

    public void mouseEntered(MouseEvent e) {
    // TODO Auto-generated method stub

    }

    public void mouseClicked(MouseEvent e) {
    // TODO Auto-generated method stub
    createImage();
    }
    });


    f.pack();
    f.setVisible(true);

    AWTUtilities.setWindowOpacity(f, 0.1f);
    // AWTUtilities.setWindowOpaque(f, false); //window does not support this effects

    }

    private void createImage(){

    System.out.println("robot start");

    Robot robot = null;
    try {
    robot = new Robot();
    } catch (AWTException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }

    Rectangle screenRect = null;

    screenRect = new Rectangle(new Dimension(x2,y2));
    screenRect.setLocation(x1, y1);

    BufferedImage image = robot.createScreenCapture(screenRect);

    FileOutputStream fos = null;
    try {
    fos = new FileOutputStream(new File("F:\\print.jpg"));
    } catch (FileNotFoundException e1) {
    // TODO Auto-generated catch block
    e1.printStackTrace();
    }

    try {
    ImageIO.write(image, "JPG", fos);
    } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    }
    }


    public static void main(String[] args) {

    final PrintScreen ps = new PrintScreen();

    SwingUtilities.invokeLater(new Runnable(){
    public void run(){
    ps.createAndShowUI();
    }
    });

    }

    }
      

  7.   

    单 '截图' button
    左键点一位置, 然后拉住左键松手
    拉出的矩形为截图区域。双击屏幕 保存和QQ截图差不多,但是做的没人家的好