CristianPalmaSola10, também tive esta idéia, mas não posso implementar, imagine no cliente aparecendo a tela e desaparecendo, estou praticamente reinventando a roda, pois o iReport não esta suprindo as necessidades de alguns relatórios dinâmicos que possuo.
ViniGodoy, não consegui implementar o que me passou, continuou me retornando uma imagem toda preta, segue em anexo o que já consegui desenvolver.
public class Main {
public static void main(String[] args0){
new SaveImage(new FrameTeste());
}
}
public class SaveImage {
/**
* Salva Imagem.
* @param frame JFrame que vai ser impresso.
*/
public SaveImage(JFrame frame) {
BufferedImage bImage = new BufferedImage(frame.getWidth(), frame.getHeight(), BufferedImage.TYPE_INT_RGB);
Graphics g = bImage.getGraphics();
// Conforme interpretado
frame.getContentPane().paint(g);
try {
File file = new File("teste" + File.separator + "teste.png");
ImageIO.write(bImage, "png", file);
} catch (IOException ioe) {
ioe.getMessage();
}
// Conforme interpretado
g.dispose();
}
}
public class FrameTeste extends JFrame{
private JButton button1, button2;
public FrameTeste(){
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setSize(400, 400);
this.setLayout(null);
this.setLocationRelativeTo(null);
this.button1 = new JButton("Teste");
this.button1.setBounds(10, 10, 200, 50);
this.add(this.button1);
this.button2 = new JButton("Teste 2");
this.button2.setBounds(70, 70, 200, 50);
this.add(this.button2);
}
}