【发布时间】:2013-05-13 16:33:48
【问题描述】:
我正在尝试从动态 html 布局呈现图像。如何根据html内表格的高度和宽度动态设置图像的宽度和高度。
我的意思是如何从html 中找到表width(x) 和height(y)?
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>
【问题讨论】:
-
您可能需要使用标签的首选尺寸。现在,问题是您将标签的大小强制为
(x,y)。尽快发布SSCCE 以获得更好的帮助
标签: java html swing jlabel bufferedimage