码迷,mamicode.com
首页 > 编程语言 > 详细

java库Html2Image:实现html转图片功能

时间:2014-08-14 20:09:39      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   java   os   io   文件   

package com.ky.util;

import gui.ava.html.image.generator.HtmlImageGenerator;

/**
 *  
 */
public class Html2ImageTest {

public static void main(String[] args){
HtmlImageGenerator imageGenerator = new HtmlImageGenerator();
String htmlstr = "<table width=‘654‘ cellpadding=‘0‘ cellspacing=‘0‘ bordercolor=‘#FFFFFF‘><tr><td><img src=‘http://www.apkfather.com/yhqserver/images/mdl.jpg‘/></td><td><img src=‘http://www.apkfather.com/yhqserver/images/mdl.jpg‘/></td><td><img src=‘http://www.apkfather.com/yhqserver/images/mdl.jpg‘/></td></tr><tr><td><img src=‘http://www.apkfather.com/yhqserver/images/mdl.jpg‘/></td><td><img src=‘http://www.apkfather.com/yhqserver/images/mdl.jpg‘/></td><td><img src=‘http://www.apkfather.com/yhqserver/images/mdl.jpg‘/></td></tr><tr><td><img src=‘http://www.apkfather.com/yhqserver/images/mdl.jpg‘/></td><td><img src=‘http://www.apkfather.com/yhqserver/images/mdl.jpg‘/></td><td><img src=‘http://www.apkfather.com/yhqserver/images/mdl.jpg‘/></td></tr><tr><td><img src=‘http://www.apkfather.com/yhqserver/images/mdl.jpg‘/></td></tr></table>";
imageGenerator.loadHtml(htmlstr);
imageGenerator.getBufferedImage();
imageGenerator.saveAsImage("d:/hello-world.png");
imageGenerator.saveAsHtmlWithMap("hello-world.html", "hello-world.png");
}
}

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. (设置生成图片大小)

 jar包支持:html2image-0.9.jar

转自:http://blog.csdn.net/luohaobubu/article/details/7414554

java库Html2Image:实现html转图片功能,布布扣,bubuko.com

java库Html2Image:实现html转图片功能

标签:style   blog   http   color   java   os   io   文件   

原文地址:http://www.cnblogs.com/wikid/p/3913070.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!