Search in sources :

Example 1 with ImageComponent2D

use of javax.media.j3d.ImageComponent2D 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;
}
Also used : GraphicsContext3D(javax.media.j3d.GraphicsContext3D) Point3f(javax.vecmath.Point3f) ImageComponent2D(javax.media.j3d.ImageComponent2D) Raster(javax.media.j3d.Raster) Rectangle(java.awt.Rectangle) IOException(java.io.IOException) BufferedImage(java.awt.image.BufferedImage)

Aggregations

Rectangle (java.awt.Rectangle)1 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 GraphicsContext3D (javax.media.j3d.GraphicsContext3D)1 ImageComponent2D (javax.media.j3d.ImageComponent2D)1 Raster (javax.media.j3d.Raster)1 Point3f (javax.vecmath.Point3f)1