Hi,

        I am working on a 3D object viewer, in Java3D.  One of the
functionalities I'd
like to implement is the capability to take a snapshot of the model, that is
copying the content of the Canvas3D to a JPEG file.  I currently have a class
that extends Canvas3D, Viewer3D, that overrides the postSwap() method, in which
I do the processing.  Unfortunately, the call to the readRaster(Raster) method
crashes opengl32.dll every time.  Could you tell me what is wrong with my code? 
I am using Java 2 and Java3D 1.1, all this running on Windows 95.


        Thank you very much!

----------
/* Code */

// the raster that will contain the captured image
private Raster rasSnapshot;

// this is set to true when a snapshot must be taken
private boolean bTakeSnapshot = false;


public void takeSnapshot(String filename) {
    bTakeSnapshot = true;
    postSwap();

    while (bTakeSnapshot)
        Thread.currentThread().yield();

    BufferedImage bi = rasSnapshot.getImage().getImage();
    FileOutputStream fOut = null;
    try {
        fOut = new FileOutputStream(filename);
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(fOut);
        encoder.encode(bi);
    } catch (ImageFormatException ife) {
    } catch (IOException ioe) {
    } finally {
        if (fOut != null) {
            try {
                fOut.close();
            } catch (IOException ioe2) {
            }
        }
    }
}

public void postSwap() {
    // original method
    super.postSwap();

   // takes a snapshot if requested
    if (bTakeSnapshot) {
        bTakeSnapshot = false;

        Dimension d = getSize();
        BufferedImage bImage = new BufferedImage(d.width, d.height,
            BufferedImage.TYPE_INT_ARGB);
        ImageComponent2D imgComp = new ImageComponent2D(
            ImageComponent2D.FORMAT_RGB, bImage);
        rasSnapshot = new Raster(new Point3f(), Raster.RASTER_COLOR,
            0, 0, d.width, d.height, imgComp, null);

System.out.println("Before readRaster()!");
        getGraphicsContext3D().readRaster(rasSnapshot);
System.out.println("After readRaster()!");
    }
}
begin:vcard 
n:Bilodeau;Guillaume
tel;work:(613) 991-5037
x-mozilla-html:FALSE
org:National Research Council Canada;Visual Information Technology
adr:;;;;;;
version:2.1
email;internet:[EMAIL PROTECTED]
title:Software Engineer
x-mozilla-cpt:;-1
fn:Guillaume Bilodeau
end:vcard

Reply via email to