html转图⽚(html2image)需要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.MalformedURLException;
import java.URISyntaxException;
import java.URL;
import javax.imageio.ImageIO;
import gui.ava.ator.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.close();
str=new String(buffer,"GBK");
} catch (IOException e) {
e.printStackTrace();
}
imageGenerator.loadHtml(str);
try {
Thread.sleep(800);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}html代码转链接
imageGenerator.saveAsImage("d:/hell.png");
//        imageGenerator.saveAsHtmlWithMap(”hello-world.html”, “hello-world.png”);
System.out.println("test");
}
}
// html2image  api介绍
HtmlImageGenerator Methods
loadUrl(url) - Loads HTML from URL object or URL string. (从url载⼊html)
loadHtml(html) - Loads HTML source. (载⼊本地html)
saveAsImage(file) - Save loaded HTML as image. (以图⽚形式保存html)
saveAsHtmlWithMap(file, imageUrl) - Creates an HTML file containing client-side image-map <map>generated from HTML's links. (创建⼀个HTML⽂件包含客户端image-map)
getLinks() - List all links in the HTML document and their corresponding href, target, title, position and dimension. (列出所有在HTML⽂档的链接和相应href、⽬标、头衔、位置和尺⼨)
getBufferedImage() - Get AWT buffered image of the HTML. (获得awt,html缓冲后的图⽚)
getLinksMapMarkup(mapName) - Get HTML snippet of the client-side image-map <map> generated from the links.
(HTML代码段⾥获得的客户端image-map <;地图>产⽣的链接)
get/setOrientation(orientation) - Get/Set document orientation (left-to-right or right-to-left). (get/set⽂本定位)
get/setSize(dimension) - Get/Set size of the generated image. (设置⽣成图⽚⼤⼩)

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。