Ciao a tutti...
Nel mio programma ho un pannello dove l'utente può disegnare. Ho quindi la necessità di salvare il JPanel con il disegno fatto dall'utente come immagine. Come fare?
Ho scritto questo codice:

codice:
private void saveComponentAsJPEG(Component myComponent, String filename) {
        Dimension size = myComponent.getSize();
        BufferedImage myImage =new BufferedImage(size.width,
        size.height,BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = myImage.createGraphics();
        myComponent.paint(g2);
        try {
            OutputStream out = new FileOutputStream(filename);
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            encoder.encode(myImage);
            out.close();}
            catch (Exception e) { System.out.println(e);}
        }
Salva un'immagine ma tutta nera. Come posso fare??