我正在尝试从动态 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>