org.proteinshader.gui.viewing
Class ScreenShot
java.lang.Object
org.proteinshader.gui.viewing.ScreenShot
public class ScreenShot
- extends Object
Knows how to take a screen shot of the image on a GLCanvas and save it as a
JPEG, PNG, or GIF file.
The image format and the file to write to can be set through the constructor,
while the canvas and current GL object are passed as arguments to the capture()
method. The GL object must be current (obtained from within the display()
method of the Renderer, which implements the GLEventListener interface).
TRANSPARENCY: PNG files can be saved with transparent background pixels.
The JPEG format does not support transparency.
The GL object is used to obtain RGB bytes from the GL_BACK color
buffer. The RGB bytes need to be converted into integers because the
Java BufferedImage object and Java ImageIO.write() method expect
integers. When the RGB bytes are converted into integers, the
y-axis is deliberately inverted because OpenGL and the Java AWT
follow different conventions. In Java, the origin is at the top
left of a canvas and positive y increases in the downward direction,
while in OpenGL the origin of a canvas is at the bottom left and
positive y increases in the upwards direction. The x-axis is the
same in both systems.
If an error occurs when capture() is executed, a ScreenShotException
will be thrown. In addition to a short error message, the requested
format and the File object (for the file to write to) will be
stored in the ScreenShotException so they can be retrieved with
getFormat() and getFile(), respectively. If a lower level exception
is rethrown as a ScreenShotException, the message from the
lower-level exception will be included so that it can be retrieved
with getLowerLevelMessage().
Method Summary |
void |
capture(GL gl,
GLAutoDrawable canvas)
Take a screen shot of the canvas and saves it to a PNG, JPG, or GIF file. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ScreenShot
public ScreenShot(ImageFormatEnum format,
File file)
- Constructs a ScreenShot. The file to save to and the image format type
(PNG, INVISIBLE_CANVAS_PNG, JPEG, or GIF) must be specified at construction
time.
TRANSPARENCY:
If transparency is not requested, then the buffered image used to write the
image file will be of type RGB and, consequently, alpha values will be
ignored. If, on the other hand, transparency (INVISIBLE_CANVAS_PNG) is
requested, then the buffered image will be changed to type ARGB. Using
ARGB will result in a transparent background for the PNG file because the
background pixels for the canvas always have an alpha value of 0.0.
- Parameters:
format
- the image format.file
- the file to save the screen shot to.
capture
public void capture(GL gl,
GLAutoDrawable canvas)
throws ScreenShotException
- Take a screen shot of the canvas and saves it to a PNG, JPG, or GIF file.
- Parameters:
gl
- the current GL object.canvas
- the GLCanvas object to capture the image from.
- Throws:
ScreenShotException
- If the screen shot cannot be captured.
Copyright © 2007-2008