Hi Matt,

Here's a routine that I use.  I cut some of my application specific code
out, but it should do the trick.
 
    /**
     * Convert the bean to a jpg file.
     * @param guiObj the GUI Object to be converted to a jpg file.
     * In this case guiObj is a subclass of a JComponent.
     */
    public void writeJPEG(Object guiObj) {
        //
        // Get the bounds of the bean.
        //
        Rectangle r = ((Component) guiObj).getBounds();
        int w=r.width;
        int h=r.height;

        BufferedImage bi = new BufferedImage(w, h,
BufferedImage.TYPE_3BYTE_BGR);
        Graphics2D big = bi.createGraphics();
        big.setBackground(Color.white);
        big.clearRect(0, 0, w, h);
        //
        // Invoke the method to paint it on the buffered image.
        //
        ((Component) guiObj).paint(big);
        //
        // Write the JPEG to a file.
        //
        try {
            File file = new File(jpgDir + "/image.jpg");
            FileOutputStream out = new FileOutputStream(file);
            //
                // Encodes buffered image as a JPEG data stream
            //
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam(bi);
            param.setQuality(1.0f, false);
            encoder.setJPEGEncodeParam(param);
            encoder.encode(bi);

            out.close();
        } catch (IOException ioe) {
            System.err.println("[writeJPEG] Exception: " + ioe);
        }
    }

FYI,
Scott
=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 2D Home Page: http://java.sun.com/products/java-media/2D/

Reply via email to