importjava.awt.Graphics2D;importjava.awt.RenderingHints;importjava.awt.geom.AffineTransform;importjava.awt.image.BufferedImage;importjava.awt.image.ColorModel;importjava.awt.image.WritableRaster;import java.io.*;import javax.imageio.*;import javax.swing.*;/*** HTML2JPG,HTML页面转图片的实现方法。
*
*@author老紫竹(Java世纪网,java2000.net)*/
public class Test extendsJFrame {public Test(String url, File file) throwsException {
JEditorPane editorPane= newJEditorPane();
editorPane.setEditable(false);
editorPane.setPage(url);
JScrollPane jsp= newJScrollPane(editorPane);
getContentPane().add(jsp);this.setLocation(0, 0);this.setVisible(true); //如果这里不设置可见,则里面的图片等无法截取//如果不延时,则图片等可能没有时间下载显示//具体的秒数需要根据网速等调整
Thread.sleep(5 * 1000);
setSize(10000, 10000);
pack();//BufferedImage image = new BufferedImage(editorPane.getWidth(),//editorPane.getHeight(