hi
I am not sure if it is the error, but I advice you to replace the absolute heigh and width values - 600 and 800 - by getHeigh() and getWidth() in your sub classed Canvas3D.
 
Alessandro
 
 


Claudio Mazzuco <[EMAIL PROTECTED]> wrote:
I've tried to use the code on the FAQ of j3d.org, to capture a frame
from a Canvas3D and save it in jpg format, but it doesn't work.
I obtain only jpegs whit garbage inside, and it's strange because the
canvas3d is well rendered.
Where i'm mistaking?

This is the main declaration:

public class MainGui extends javax.swing.JFrame {

public manage3d.render3d.CapturingCanvas3D canvas3d;

[..]

public MainGui() {
GraphicsConfiguration config =
SimpleUniverse.getPreferredConfiguration();
canvas3d = new manage3d.render3d.CapturingCanvas3D(config);

[..]
}
[...]

// here i make the snapshot
manage3d.render3d.Snapshot s = new manage3d.render3d.Snapshot();
s.captureImage(this.canvas3d);
}

This is the class who calls the jpeg creation:

public class Snapshot {
public Snapshot() {
}

pu blic static void captureImage(CapturingCanvas3D MyCanvas3D) {
MyCanvas3D.writeJPEG_ = true;
MyCanvas3D.repaint();
}

}

and this is the code of CapturingCanvas3D:

public class CapturingCanvas3D extends Canvas3D {

public boolean writeJPEG_;
private int postSwapCount_;

public CapturingCanvas3D(GraphicsConfiguration gc) {
super(gc);
postSwapCount_ = 0;
}

public void postSwap() {
if(writeJPEG_) {
System.out.println("Writing JPEG");
GraphicsContext3D ctx = getGraphicsContext3D();
// The raster components need all be set!
Raster ras = new Raster(
new Point3f(-1.0f,-1.0f,-1.0f),
Raster.RASTER_COLOR,
0,0,
800,600,
new ImageComponent2D(
ImageComponent.FORMAT_RGB,
new BufferedImage(800,600,
BufferedImage.TYPE_INT_RGB)),
null);

ctx.readRaster(ras);

// Now strip out the image info
BufferedImage img = ras.getImage().getImage();

// write that to disk....
try {
FileOutputStream out = new
FileOutputStream("c:\\Capture"+postSwapCount_+".jpg");
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
JPEGEncodeParam param =
encoder.getDefaultJPEGEncodeParam(img);
param.setQuality(0.9f,false); // 90% qualith JPEG
encoder.setJPEGEncodeParam(param);
encoder.encode(img);
writeJPEG_ = false;
out.close();
} catch ( IOException e ) {
System.out.println("I/O exception!");
}
postSwapCount_++;
}
}
}

===========================================================================
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".


Yahoo! Acesso Grátis - navegue de graça com conexão de qualidade! =========================================================================== 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".

Reply via email to