请教一个网页截图的问题 使用java来对网页截图是不可能的,你不可以使用键盘的PrintScreen后,在PhotoShop中处理不就可以了,然后再用java调用来在网页上显示 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 如果要这样就简单了。用js模拟下PrintScreen键后再去粘帖保存下图片即可。问题是我认为这样做过于复杂了,我希望达到的效果是:在页面上点击一个按钮然后出来一个选择截取范围的选择域,像QQ截图那样。在选取完范围后就可以直接让我选择图片保存路径和文件名之类的了。 csdn也有这样的截图效果,你上传头像时,会让你选择你要截取的选择域,但是它是针对图片的,你是直接对网页截图。 可能比较好的思路是 js + activeX控件。 QQ的截图 好像看过 你去csdn的下载去搜搜 应该有源代码的 4楼说得对,用JAVA截网页的,应该没有这种方法,但你可以按键盘上的print Screen SysRq键截取啊。当然一些截图的软件,蛮多,你网上可以找找; 如果截取图片的,CSDN确实有一个,不过不知是用什么语言做的,你可以找找相关资料。 在此先特别感谢下yinyuan1987当然也谢谢所有关注的人。 楼主你看看这个例子可以应用么import javax.swing.*;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.MouseAdapter;import java.awt.event.MouseEvent;import java.awt.event.MouseMotionListener;/*** 用Java模拟出QQ桌面截图功能* @author 五斗米 <如转载请保留作者和出处>* @blog http://blog.csdn.net/mq612*/public class Test extends JFrame {private static final long serialVersionUID = -267804510087895906L;private JButton button = null;private JLabel imgLabel = null;public Test() { button = new JButton("模拟屏幕(点右键退出)"); button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { new ScreenWindow(imgLabel); } catch (Exception e1) { JOptionPane.showConfirmDialog(null, "出现意外错误!", "系统提示", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } } }); JPanel pane = new JPanel(); pane.setBackground(Color.WHITE); imgLabel = new JLabel(); pane.add(imgLabel); JScrollPane spane = new JScrollPane(pane); this.getContentPane().add(button, BorderLayout.NORTH); this.getContentPane().add(spane); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setSize(300, 200); this.setLocationRelativeTo(null); this.setVisible(true);}public static void main(String[] args) { new Test();}}class ScreenWindow extends JFrame {private static final long serialVersionUID = -3758062802950480258L;private boolean isDrag = false;private int x = 0;private int y = 0;private int xEnd = 0;private int yEnd = 0;public ScreenWindow(final JLabel imgLabel) throws AWTException, InterruptedException { Dimension screenDims = Toolkit.getDefaultToolkit().getScreenSize(); JLabel label = new JLabel(new ImageIcon(ScreenImage.getScreenImage(0, 0, screenDims.width, screenDims.height))); label.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR)); label.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { dispose(); } } public void mousePressed(MouseEvent e) { x = e.getX(); y = e.getY(); } public void mouseReleased(MouseEvent e) { if (isDrag) { xEnd = e.getX(); yEnd = e.getY(); if(x > xEnd){ int temp = x; x = xEnd; xEnd = temp; } if(y > yEnd){ int temp = y; y = yEnd; yEnd = temp; } try { imgLabel.setIcon(new ImageIcon(ScreenImage.getScreenImage(x, y, xEnd - x, yEnd - y))); } catch (Exception ex) { JOptionPane.showConfirmDialog(null, "出现意外错误!", "系统提示", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE); } dispose(); } } }); label.addMouseMotionListener(new MouseMotionListener() { public void mouseDragged(MouseEvent e) { if(!isDrag) isDrag = true; } public void mouseMoved(MouseEvent e) { /** 拖动过程的虚线选取框需自己实现 */ } }); this.setUndecorated(true); this.getContentPane().add(label); this.setSize(screenDims.width, screenDims.height); this.setVisible(true); this.setExtendedState(JFrame.MAXIMIZED_BOTH);}}class ScreenImage {public static Image getScreenImage(int x, int y, int w, int h) throws AWTException, InterruptedException { Robot robot = new Robot(); Image screen = robot.createScreenCapture(new Rectangle(x, y, w, h)).getScaledInstance(w, h, Image.SCALE_SMOOTH); MediaTracker tracker = new MediaTracker(new Label()); tracker.addImage(screen, 1); tracker.waitForID(0); return screen;}} 使用java来对网页截图是不可能的, 你不可以使用键盘的PrintScreen后, 在PhotoShop中处理不就可以了, 然后再用java调用来在网页上显示 Swing做到截图并不难 楼主得意思好像是在说在web得客户端截图 好像深了点 期待楼主突破后回帖:( 是啊!1楼我就说了用java来对网页截图不可能, 能截图但是不好应用到客户端截图。用applet又过于落伍。先暂时结帖了。谢谢各位。 Workflow无解小bug。 帮忙修改下正则 <menu><item text="" action=""/></menu>这是什么? jsp页面进行查询时出现乱码问题,急急急 急急!!! SSH 开发guestbook js传值的问题 ibatis 删除语句问题???? 哪位精通hibernate的高手看一下,映射异常. Help 在windows xp 下如何把java包(jdk1.3.)加入CLASSPATH变量中 求struts中文api hibernate的核心是什么,是表的映射吗
问题是我认为这样做过于复杂了,我希望达到的效果是:在页面上点击一个按钮然后出来一个选择截取范围的选择域,像QQ截图那样。在选取完范围后就可以直接让我选择图片保存路径和文件名之类的了。
但是它是针对图片的,你是直接对网页截图。
如果截取图片的,CSDN确实有一个,不过不知是用什么语言做的,你可以找找相关资料。
当然也谢谢所有关注的人。
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;/**
* 用Java模拟出QQ桌面截图功能
* @author 五斗米 <如转载请保留作者和出处>
* @blog http://blog.csdn.net/mq612
*/public class Test extends JFrame {private static final long serialVersionUID = -267804510087895906L;private JButton button = null;private JLabel imgLabel = null;public Test() {
button = new JButton("模拟屏幕(点右键退出)");
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
new ScreenWindow(imgLabel);
} catch (Exception e1) {
JOptionPane.showConfirmDialog(null, "出现意外错误!", "系统提示", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
}
}
});
JPanel pane = new JPanel();
pane.setBackground(Color.WHITE);
imgLabel = new JLabel();
pane.add(imgLabel);
JScrollPane spane = new JScrollPane(pane);
this.getContentPane().add(button, BorderLayout.NORTH);
this.getContentPane().add(spane);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 200);
this.setLocationRelativeTo(null);
this.setVisible(true);
}public static void main(String[] args) {
new Test();
}
}class ScreenWindow extends JFrame {private static final long serialVersionUID = -3758062802950480258L;private boolean isDrag = false;private int x = 0;private int y = 0;private int xEnd = 0;private int yEnd = 0;public ScreenWindow(final JLabel imgLabel) throws AWTException, InterruptedException {
Dimension screenDims = Toolkit.getDefaultToolkit().getScreenSize();
JLabel label = new JLabel(new ImageIcon(ScreenImage.getScreenImage(0, 0, screenDims.width, screenDims.height)));
label.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
label.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getButton() == MouseEvent.BUTTON3) {
dispose();
}
} public void mousePressed(MouseEvent e) {
x = e.getX();
y = e.getY();
} public void mouseReleased(MouseEvent e) {
if (isDrag) {
xEnd = e.getX();
yEnd = e.getY();
if(x > xEnd){
int temp = x;
x = xEnd;
xEnd = temp;
}
if(y > yEnd){
int temp = y;
y = yEnd;
yEnd = temp;
}
try {
imgLabel.setIcon(new ImageIcon(ScreenImage.getScreenImage(x, y, xEnd - x, yEnd - y)));
} catch (Exception ex) {
JOptionPane.showConfirmDialog(null, "出现意外错误!", "系统提示", JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE);
}
dispose();
}
}
});
label.addMouseMotionListener(new MouseMotionListener() {
public void mouseDragged(MouseEvent e) {
if(!isDrag)
isDrag = true;
} public void mouseMoved(MouseEvent e) {
/** 拖动过程的虚线选取框需自己实现 */
}
});
this.setUndecorated(true);
this.getContentPane().add(label);
this.setSize(screenDims.width, screenDims.height);
this.setVisible(true);
this.setExtendedState(JFrame.MAXIMIZED_BOTH);
}
}class ScreenImage {public static Image getScreenImage(int x, int y, int w, int h) throws AWTException, InterruptedException {
Robot robot = new Robot();
Image screen = robot.createScreenCapture(new Rectangle(x, y, w, h)).getScaledInstance(w, h, Image.SCALE_SMOOTH);
MediaTracker tracker = new MediaTracker(new Label());
tracker.addImage(screen, 1);
tracker.waitForID(0);
return screen;
}
}
你不可以使用键盘的PrintScreen后,
在PhotoShop中处理不就可以了,
然后再用java调用来在网页上显示
1楼我就说了
用java来对网页截图不可能,