当先锋百科网

首页 1 2 3 4 5 6 7

需要jar包

实现 package cn; //import com.yanhui.util._html2jpg; import java.awt.*; import java.awt.event.KeyEvent; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; import java.io.IOException; import java.net.MalformedURLException; import java.net.URISyntaxException; import java.net.URL; import javax.imageio.ImageIO; import gui.ava.html.image.generator.HtmlImageGenerator; public class Test { public static void main(String[] args) { HtmlImageGenerator imageGenerator = new HtmlImageGenerator(); String str=""; File file=new File("D://222.html");//本地文件 try { FileInputStream in=new FileInputStream(file); // size 为字串的长度 ,这里一次性读完 int size=in.available(); byte[] buffer=new byte[size]; in.read(buffer); in.close(); str=new String(buffer,"GBK"); } catch (IOException e) { e.printStackTrace(); } imageGenerator.loadHtml(str); imageGenerator.getBufferedImage(); try { Thread.sleep(800); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } imageGenerator.saveAsImage("d:/hell.png"); // imageGenerator.saveAsHtmlWithMap(”hello-world.html”, “hello-world.png”); System.out.println("test"); } }

HtmlImageGenerator Methods