com.sun.opengl.util
Class Screenshot

java.lang.Object
  extended bycom.sun.opengl.util.Screenshot

public class Screenshot
extends Object

Utilities for taking screenshots of OpenGL applications.


Method Summary
static BufferedImage readToBufferedImage(int width, int height)
          Takes a screenshot of the current OpenGL drawable to a BufferedImage.
static BufferedImage readToBufferedImage(int width, int height, boolean alpha)
          Takes a screenshot of the current OpenGL drawable to a BufferedImage.
static BufferedImage readToBufferedImage(int x, int y, int width, int height, boolean alpha)
          Takes a screenshot of the current OpenGL drawable to a BufferedImage.
static void writeToFile(File file, int width, int height)
          Takes a screenshot of the current OpenGL drawable to the specified file on disk using the ImageIO package.
static void writeToFile(File file, int width, int height, boolean alpha)
          Takes a screenshot of the current OpenGL drawable to the specified file on disk using the ImageIO package.
static void writeToFile(File file, int x, int y, int width, int height, boolean alpha)
          Takes a screenshot of the current OpenGL drawable to the specified file on disk using the ImageIO package.
static void writeToTargaFile(File file, int width, int height)
          Takes a fast screenshot of the current OpenGL drawable to a Targa file.
static void writeToTargaFile(File file, int width, int height, boolean alpha)
          Takes a fast screenshot of the current OpenGL drawable to a Targa file.
static void writeToTargaFile(File file, int x, int y, int width, int height, boolean alpha)
          Takes a fast screenshot of the current OpenGL drawable to a Targa file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

writeToTargaFile

public static void writeToTargaFile(File file,
                                    int width,
                                    int height)
                             throws GLException,
                                    IOException
Takes a fast screenshot of the current OpenGL drawable to a Targa file. Requires the OpenGL context for the desired drawable to be current. This is the fastest mechanism for taking a screenshot of an application. Contributed by Carsten Weisse of Bytonic Software (http://bytonic.de/).

No alpha channel is written with this variant.

Parameters:
file - the file to write containing the screenshot
width - the width of the current drawable
height - the height of the current drawable
Throws:
GLException - if an OpenGL context was not current or another OpenGL-related error occurred
IOException - if an I/O error occurred while writing the file

writeToTargaFile

public static void writeToTargaFile(File file,
                                    int width,
                                    int height,
                                    boolean alpha)
                             throws GLException,
                                    IOException
Takes a fast screenshot of the current OpenGL drawable to a Targa file. Requires the OpenGL context for the desired drawable to be current. This is the fastest mechanism for taking a screenshot of an application. Contributed by Carsten Weisse of Bytonic Software (http://bytonic.de/).

Parameters:
file - the file to write containing the screenshot
width - the width of the current drawable
height - the height of the current drawable
alpha - whether the alpha channel should be saved. If true, requires GL_EXT_abgr extension to be present.
Throws:
GLException - if an OpenGL context was not current or another OpenGL-related error occurred
IOException - if an I/O error occurred while writing the file

writeToTargaFile

public static void writeToTargaFile(File file,
                                    int x,
                                    int y,
                                    int width,
                                    int height,
                                    boolean alpha)
                             throws GLException,
                                    IOException
Takes a fast screenshot of the current OpenGL drawable to a Targa file. Requires the OpenGL context for the desired drawable to be current. This is the fastest mechanism for taking a screenshot of an application. Contributed by Carsten Weisse of Bytonic Software (http://bytonic.de/).

Parameters:
file - the file to write containing the screenshot
x - the starting x coordinate of the screenshot, measured from the lower-left
y - the starting y coordinate of the screenshot, measured from the lower-left
width - the width of the desired screenshot area
height - the height of the desired screenshot area
alpha - whether the alpha channel should be saved. If true, requires GL_EXT_abgr extension to be present.
Throws:
GLException - if an OpenGL context was not current or another OpenGL-related error occurred
IOException - if an I/O error occurred while writing the file

readToBufferedImage

public static BufferedImage readToBufferedImage(int width,
                                                int height)
                                         throws GLException
Takes a screenshot of the current OpenGL drawable to a BufferedImage. Requires the OpenGL context for the desired drawable to be current. Note that the scanlines of the resulting image are flipped vertically in order to correctly match the OpenGL contents, which takes time and is therefore not as fast as the Targa screenshot function.

No alpha channel is read back with this variant.

Parameters:
width - the width of the current drawable
height - the height of the current drawable
Throws:
GLException - if an OpenGL context was not current or another OpenGL-related error occurred

readToBufferedImage

public static BufferedImage readToBufferedImage(int width,
                                                int height,
                                                boolean alpha)
                                         throws GLException
Takes a screenshot of the current OpenGL drawable to a BufferedImage. Requires the OpenGL context for the desired drawable to be current. Note that the scanlines of the resulting image are flipped vertically in order to correctly match the OpenGL contents, which takes time and is therefore not as fast as the Targa screenshot function.

Parameters:
width - the width of the current drawable
height - the height of the current drawable
alpha - whether the alpha channel should be read back. If true, requires GL_EXT_abgr extension to be present.
Throws:
GLException - if an OpenGL context was not current or another OpenGL-related error occurred

readToBufferedImage

public static BufferedImage readToBufferedImage(int x,
                                                int y,
                                                int width,
                                                int height,
                                                boolean alpha)
                                         throws GLException
Takes a screenshot of the current OpenGL drawable to a BufferedImage. Requires the OpenGL context for the desired drawable to be current. Note that the scanlines of the resulting image are flipped vertically in order to correctly match the OpenGL contents, which takes time and is therefore not as fast as the Targa screenshot function.

Parameters:
x - the starting x coordinate of the screenshot, measured from the lower-left
y - the starting y coordinate of the screenshot, measured from the lower-left
width - the width of the desired screenshot area
height - the height of the desired screenshot area
alpha - whether the alpha channel should be read back. If true, requires GL_EXT_abgr extension to be present.
Throws:
GLException - if an OpenGL context was not current or another OpenGL-related error occurred

writeToFile

public static void writeToFile(File file,
                               int width,
                               int height)
                        throws IOException,
                               GLException
Takes a screenshot of the current OpenGL drawable to the specified file on disk using the ImageIO package. Requires the OpenGL context for the desired drawable to be current. This is not the fastest mechanism for taking a screenshot but may be more convenient than others for getting images for consumption by other packages. The file format is inferred from the suffix of the given file.

No alpha channel is saved with this variant.

Parameters:
file - the file to write containing the screenshot
width - the width of the current drawable
height - the height of the current drawable
Throws:
GLException - if an OpenGL context was not current or another OpenGL-related error occurred
IOException - if an I/O error occurred or if the file could not be written to disk due to the requested file format being unsupported by ImageIO

writeToFile

public static void writeToFile(File file,
                               int width,
                               int height,
                               boolean alpha)
                        throws IOException,
                               GLException
Takes a screenshot of the current OpenGL drawable to the specified file on disk using the ImageIO package. Requires the OpenGL context for the desired drawable to be current. This is not the fastest mechanism for taking a screenshot but may be more convenient than others for getting images for consumption by other packages. The file format is inferred from the suffix of the given file.

Note that some file formats, in particular JPEG, can not handle an alpha channel properly. If the "alpha" argument is specified as true for such a file format it will be silently ignored.

Parameters:
file - the file to write containing the screenshot
width - the width of the current drawable
height - the height of the current drawable
alpha - whether an alpha channel should be saved. If true, requires GL_EXT_abgr extension to be present.
Throws:
GLException - if an OpenGL context was not current or another OpenGL-related error occurred
IOException - if an I/O error occurred or if the file could not be written to disk due to the requested file format being unsupported by ImageIO

writeToFile

public static void writeToFile(File file,
                               int x,
                               int y,
                               int width,
                               int height,
                               boolean alpha)
                        throws IOException,
                               GLException
Takes a screenshot of the current OpenGL drawable to the specified file on disk using the ImageIO package. Requires the OpenGL context for the desired drawable to be current. This is not the fastest mechanism for taking a screenshot but may be more convenient than others for getting images for consumption by other packages. The file format is inferred from the suffix of the given file.

Note that some file formats, in particular JPEG, can not handle an alpha channel properly. If the "alpha" argument is specified as true for such a file format it will be silently ignored.

Parameters:
file - the file to write containing the screenshot
x - the starting x coordinate of the screenshot, measured from the lower-left
y - the starting y coordinate of the screenshot, measured from the lower-left
width - the width of the current drawable
height - the height of the current drawable
alpha - whether an alpha channel should be saved. If true, requires GL_EXT_abgr extension to be present.
Throws:
GLException - if an OpenGL context was not current or another OpenGL-related error occurred
IOException - if an I/O error occurred or if the file could not be written to disk due to the requested file format being unsupported by ImageIO


Copyright 2005 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms.