use of javax.media.j3d.GraphicsContext3D in project ffx by mjschnie.
the class GraphicsCanvas method postSwap.
/**
* {@inheritDoc}
*
* Image capture from the 3D Canvas is done in postSwap.
*/
@Override
public void postSwap() {
if (!imageCapture || mainPanel.getHierarchy().getActive() == null) {
return;
}
GraphicsContext3D ctx = getGraphicsContext3D();
Rectangle rect = getBounds();
BufferedImage img = new BufferedImage(rect.width, rect.height, BufferedImage.TYPE_INT_RGB);
ImageComponent2D comp = new ImageComponent2D(ImageComponent.FORMAT_RGB, img);
Raster ras = new Raster(new Point3f(-1.0f, -1.0f, -1.0f), Raster.RASTER_COLOR, 0, 0, rect.width, rect.height, comp, null);
ctx.readRaster(ras);
img = ras.getImage().getImage();
try {
if (!ImageIO.write(img, imageFormat.toString(), imageName)) {
logger.warning(String.format(" No image writer was found for %s.\n Please try a different image format.\n", imageFormat.toString()));
imageName.delete();
} else {
logger.info(String.format(" %s was captured.", imageName));
}
} catch (IOException e) {
logger.warning(e.getMessage());
}
imageCapture = false;
}
Aggregations