急求 Invoke.jar 替代工具 最近做了个屏幕鼠标移动监听与屏幕取色的功能。用到了Invoke.jar这个API。用了一段时间,挺好。今天突然发现丫要收费。不买就用不了这功能了。求Invoke.jar的替代工具。或给思路实现鼠标屏幕取色。谢谢各位。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 标记下,下午做一下。不过还得看看 颜色的类api。 看了下,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);这个类还可以实现截屏功能! 具体代码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); }}需要再做下 鼠标拉框的 方法 要有鼠标事件必须要有个frame对象啊。楼主你要做出来个什么东西?达到什么效果呢? Robot 截的图,没有鼠标位置。 实验下这个截屏类,楼主多看看吧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(); } }); } } 单 '截图' button左键点一位置, 然后拉住左键松手拉出的矩形为截图区域。双击屏幕 保存和QQ截图差不多,但是做的没人家的好 java菜鸟求助! 错在哪呢? Java中类的继承的一个问题(子类对象调用了父类的private方法) 将一个GBK格式的文件转换为UTF-8的文件???(多谢,急) Properties类文件输出问题 进程问题 把数字写到文件中出错 switch(exception)case 中 exception的值为String类型怎么出错,怎样转换成基本类型 ? 在while用=而不用==为什么bool型的可以? 高手请赐招:数字签名与数字认证的区别,尤其是概念上的区别。谢谢! 关于HTTP、TCP的困惑!! 数据库连接
不过还得看看 颜色的类api。
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);
这个类还可以实现截屏功能!
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);
}}
需要再做下 鼠标拉框的 方法
楼主你要做出来个什么东西?达到什么效果呢?
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();
}
});
}
}
左键点一位置, 然后拉住左键松手
拉出的矩形为截图区域。双击屏幕 保存和QQ截图差不多,但是做的没人家的好