java庫Html2Image:實現html轉圖片功能


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM