国产gaysexchina男同gay,japanrcep老熟妇乱子伦视频,吃奶呻吟打开双腿做受动态图,成人色网站,国产av一区二区三区最新精品

App下載
首頁javaimageJava Graphics - 如何渲染HTML和保存圖像

Java Graphics - 如何渲染HTML和保存圖像

我們想知道如何渲染HTML和保存圖像。
import java.awt.Graphics;
import java.awt.GraphicsEnvironment;
import java.awt.image.BufferedImage;
import java.io.File;

import javax.imageio.ImageIO;
import javax.swing.JEditorPane;

public class Main {

  public static void main(String[] args) throws Exception {
    String html = "<h1>Hello, world.</h1>";
    int width = 200, height = 100;

    BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment()
        .getDefaultScreenDevice().getDefaultConfiguration()
        .createCompatibleImage(width, height);

    Graphics graphics = image.createGraphics();

    JEditorPane jep = new JEditorPane("text/html", html);
    jep.setSize(width, height);
    jep.print(graphics);

    ImageIO.write(image, "png", new File("Image.png"));
  }
}