There have been a number of bits and pieces floating around regarding
image capture from a Canvas3D. I've included my extension of
Canvas3D for doing this below.
It seems to work fine but I had a few questions that perhaps someone
out there could answer, which might also be of interest to others...
Question 1) Notice that I have a method getImage() that returns an
Image object containing the captured canvas image. This method must
be called from a separate thread otherwise the Canvas content will
subsequently be frozen (i.e. Java 3D will no longer update it). Am I
missing something or is the need for a separate thread standard
operating procedure for doing image capture?
Question 2) In the same method, getImage(), I've commented out the
code to set the capture request flag. It doesn't seem to be needed.
Perhaps it is because I'm only capturing relatively static images. If
the canvas content was continuously changing then would the capture
request flag be needed? Is this the correct way to implement the
capture request in the postSwap?
thanks
--jon
-----------------------------------------------------
package j3dui.utils.app;
import java.awt.*;
import java.awt.image.BufferedImage;
import javax.media.j3d.*;
import javax.vecmath.*;
import j3dui.utils.Debug;
/**
This class represents a view's "display space". It must be
added to the application frame in order to see the associated
view of the world. It also provides image capture support
through getImage(), such as for printing.
@author Jon Barrilleax,
copyright (c) 1999 Jon Barrilleaux,
All Rights Reserved.
*/
public class AppDisplay extends Canvas3D {
// public interface =========================================
/**
Constructs a new AppDisplay(). Must be associated with an
AppView in order to use it.
*/
public AppDisplay() {
super(null);
}
/**
Gets a snapshot image of the current display. MUST be called
from a separate thread otherwise the canvas will become
frozen. Also, ONLY works for the first display added to the
frame (bug in Canvas3D?).
@return New image captured from the display.
*/
public Image getImage() {
// build raster with canvas size
ImageComponent2D image2d = new ImageComponent2D(
ImageComponent.FORMAT_RGB, getWidth(), getHeight());
Raster raster = new Raster(new Point3f(),
Raster.RASTER_COLOR, 0, 0, getWidth(),
getHeight(), image2d, null);
// wait for raster capture
// doesn't seem to be needed
// _captureRequest = true;
// repaint();
//
// while(_captureRequest) {
// Thread.currentThread().yield();
// }
getGraphicsContext3D().readRaster(raster);
return raster.getImage().getImage();
}
// Canvas overrides
public Dimension getMinimumSize() {
return new Dimension(100, 100);
}
// Canvas3D overrides
/**
Called by the renderer. Do not use this method directly,
instead use getImage() to coordinate everything and to get
the image.
*/
public void postSwap()
{
super.postSwap();
if(Debug.getEnabled()){Debug.println("utils.render",
"RENDER:AppDisplay:postSwap: swap done");}
if (_captureRequest) {
// capture dispay image in raster
_captureRequest = false;
if(Debug.getEnabled()){Debug.println("utils.print",
"PRINT:AppDisplay:postSwap: capture done");}
}
}
// personal body ============================================
/** True if a canvas capture has been requested. */
private boolean _captureRequest;
}
____________________ Peculiar Technologies ____________________
Jon Barrilleaux 3800 Lake Shore Ave. Purveyors of
[EMAIL PROTECTED] Oakland, CA 94610 Alternate Reality
510.444.4370 voc Augmented Simulation
510.444.0231 fax www.augsim.com and 3D Solutions