Hi Stam, I've had that same problem and now I don't. I don't understand why I did and I don't understand why I don't. There seems to be some *magic* involved. Serioiusly, though, maybe someone on this list knows what causes the problem. Anyway, below you will find my working solution.
Raffi -----Original Message----- From: stam echad [mailto:[EMAIL PROTECTED]] Sent: Wednesday, September 25, 2002 6:25 AM To: [EMAIL PROTECTED] Subject: [JAVA3D] Screen Capturing resulting in Blank images Hi, I've tried to use the screen capturing functions as described in http://www.j3d.org/faq/capturing.html. Whenever I run my program and press the 'capture' button, the Canvas flashes grey for a few seconds and then a picture is saved as Jpg file. The problem is that the saved Jpg's are very often the blank grey flash instead of the contents of the Canvas3D I wanted to save. Has anyone encountered this problem and could anyone please provide me with some help in the matter? Thank You /******************************************************************* Copyright 2002. Science Applications International Corportion (SAIC) Raffi J. Kasparian 1525 WILSON BOULEVARD SUITE 800 ARLINGTON, VA 22209 *******************************************************************/ package orbiter; import com.sun.j3d.utils.image.*; import java.awt.*; import java.io.*; import javax.media.j3d.*; import javax.vecmath.*; import java.awt.image.BufferedImage; import com.sun.image.codec.jpeg.*; import java.util.*; public class CaptureCanvas3D extends Canvas3D{ private Timer timer = new Timer(); private Vector captureRequests = new Vector(); public CaptureCanvas3D( GraphicsConfiguration gc ){ super( gc ); } public void captureOne( File file ){ ImageHandler request = createRequest( file ); synchronized( captureRequests ){ captureRequests.add( request ); } getView().repaint(); } public void postSwap(){ boolean pendingRequests = false; synchronized( captureRequests ){ if( captureRequests.size() > 0 ){ pendingRequests = true; } } if( pendingRequests ){ BufferedImage img = createBufferedImage(); handleRequests( img ); } } private void handleRequests( BufferedImage img ){ ImageHandler[] requests; synchronized( captureRequests ){ requests = (ImageHandler[])captureRequests.toArray( new ImageHandler[captureRequests.size()] ); captureRequests.clear(); } for( int i = 0; i < requests.length; ++i ){ requests[i].handleImage( img ); } } private ImageHandler createRequest( final File f ){//must be called from postSwap ImageHandler request = new ImageHandler(){ public void handleImage( BufferedImage img ){ writeToFile( img, f ); } }; return request; } private void writeToFile( BufferedImage image, File file ){ try{ FileOutputStream out = new FileOutputStream( file ); JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder( out ); JPEGEncodeParam param = encoder.getDefaultJPEGEncodeParam( image ); param.setQuality( 1.0f, false ); encoder.setJPEGEncodeParam( param ); encoder.encode( image ); out.close(); }catch ( IOException e ){ e.printStackTrace(); } } private BufferedImage createBufferedImage(){ GraphicsContext3D ctx = getGraphicsContext3D(); int w = getWidth(); int h = getHeight(); //BufferedImage bi = new BufferedImage( w, h, BufferedImage.TYPE_INT_RGB ); //BufferedImage bi = new BufferedImage( w, h, BufferedImage.TYPE_BYTE_INDEXED ); BufferedImage bi = new BufferedImage( w, h, BufferedImage.TYPE_BYTE_BINARY ); ImageComponent2D im = new ImageComponent2D( ImageComponent.FORMAT_R3_G3_B2, bi ); Raster ras = new Raster( new Point3f( -1.0f, -1.0f, -1.0f ), Raster.RASTER_COLOR, 0, 0, w, h, im, null ); ctx.readRaster( ras ); return ras.getImage().getImage(); } interface ImageHandler{ public void handleImage( BufferedImage img ); } } _________________________________________________________________ Chat with friends online, try MSN Messenger: http://messenger.msn.com =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help". =========================================================================== To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff JAVA3D-INTEREST". For general help, send email to [EMAIL PROTECTED] and include in the body of the message "help".
