如何将 a 存储JPanel
为jpeg图像,我可以搜索的解决方案会拍摄显示的快照,这不会捕获所有内容,JPanel
因为它的一部分是隐藏的。有没有办法在jpeg中获取整个图像。
此处提供的此解决方案根本无法正常工作
我目前用来拍摄 JPanel 快照的代码
if (panelx == null) {
jButton3.setText("Generate Diagram");
} else {
jButton3.setText("Generate Diagram");
jTextPane1
.setText(Messages.getString("statement2")); //$NON-NLS-1$
JFrame win = (JFrame) SwingUtilities
.getWindowAncestor(panelx.panelx);
Dimension size = win.getSize();
// BufferedImage image = new BufferedImage(size.width, size.height,
// BufferedImage.TYPE_INT_RGB);
BufferedImage image = (BufferedImage) win.createImage(size.width,
size.height);
Graphics g = image.getGraphics();
win.paint(g);
g.dispose();
try {
ImageIO.write(
image,
Messages.getString("Statement38"), new File(Messages.getString("statement5"))); //$NON-NLS-1$ //$NON-NLS-2$
} catch (IOException e) {
System.out.println("Image cannot be created");
}