0

動的 html レイアウトから画像をレンダリングしようとしています。HTML内のテーブルの高さと幅に基づいて、画像の幅と高さを動的に設定するにはどうすればよいですか。width(x)どうすればテーブルを見つけることができますheight(y)html

    JLabel label = new JLabel(html);
    label.setSize(x, y);
    BufferedImage image = new BufferedImage(label.getWidth(),label.getHeight(),BufferedImage.TYPE_INT_ARGB);
    Graphics2D g2d = (Graphics2D)image.getGraphics();
    g2d.setColor(Color.WHITE);
    g2d.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    label.paint(g2d);
    g2d.dispose();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
        ImageIO.write(image, "png", baos);
    } catch (IOException e) {
        e.printStackTrace();
    }

以下はhtmlの概要です。

<html>
<head>....</head>
<body topmargin="0" leftmargin="0"><table border=0 cellpadding=0 cellspacing=0 width=700 style='border-collapse:collapse;table-layout:fixed;width:684pt'>
......
......
</body></html>
4

1 に答える 1