|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.pearsoneduc.ip.io.PPMEncoder
Writes image data to a stream or a file encoded in PBM, PGM or PPM format, as appropriate.
The PBM, PGM and PPM formats are simple, popular formats for binary, greyscale and colour images on Unix systems. This class supports only the ASCII variants of these formats; the more compact raw binary variants are not currently supported.
A PBM, PGM or PPM header contains a two-character signature (see table below), the image width, the image height and (unless it is a PBM file) the maximum pixel value. Each of these elements are separated by whitespace. The header may also contain comment lines, each of which begin with the '#' character. By default, an encoder adds a comment giving the date and time of image creation; to prevent this, invoke the encoder's disableComments method.
Signature | Image type |
---|---|
P1 | binary (1 bit per pixel) |
P2 | greyscale (8 or 16 bits) |
P3 | RGB colour (24 bits) |
Image data are written using ASCII numeric characters. Line breaks are inserted after each row of data, and also wherever necessary to ensure that no line in the file is more than 70 characters in length.
PBM data are written as a stream of the characters '1' or '0'. By default, the inverted meaning of these values is used, as required by the official definition of the PBM format - with '1' signifying black and '0' signifying white. This can be reversed by invoking the disableBitmapInversion method.
PGM data are written as a series of ASCII decimal values, right-justified in a field four characters wide (or six characters wide in the case of 16-bit images). PPM data are written in a band-interleaved fashion - i.e., the R, G and B values are written for each pixel in turn - with each colour component's value written as for greyscale images. An extra space is inserted between each RGB triplet.
Example of use:
BufferedImage image = new BufferedImage(128, 128, BufferedImage.TYPE_BYTE_GRAY); ... PPMEncoder pgm = new PPMEncoder("test.pgm"); pgm.disableComments(); pgm.encode(image);
PPMEncoderException
,
PPMDecoder
,
BufferedImage
Constructor Summary | |
PPMEncoder()
Constructs a PPMEncoder associated with standard output. |
|
PPMEncoder(java.io.OutputStream out)
Constructs a PPMEncoder that writes to an existing OutputStream object. |
|
PPMEncoder(java.lang.String filename)
Constructs a PPMEncoder that writes to a named file. |
Method Summary | |
boolean |
bitmapInversionEnabled()
Indicates whether a binary image will be inverted when written to a PBM file, such that black and white are written as 1 and 0, respectively. |
boolean |
commentsEnabled()
Indicates whether comments may be added to a PBM, PGM or PPM header. |
void |
disableBitmapInversion()
Disables bitmap inversion when writing data in the PBM format. |
void |
disableComments()
Disables commenting of the PBM, PGM or PPM header with creation date. |
void |
enableBitmapInversion()
Enables bitmap inversion when writing data in the PBM format. |
void |
enableComments()
Enables commenting of the PBM, PGM or PPM header. |
void |
encode(java.awt.image.BufferedImage image)
Encodes the specified image using the most appropriate image format. |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Constructor Detail |
public PPMEncoder()
public PPMEncoder(java.io.OutputStream out)
out
- the destination for the image datapublic PPMEncoder(java.lang.String filename) throws java.io.IOException
filename
- Name of the file to which image data will be writtenMethod Detail |
public boolean commentsEnabled()
public void disableComments()
public void enableComments()
public boolean bitmapInversionEnabled()
public void disableBitmapInversion()
public void enableBitmapInversion()
public void encode(java.awt.image.BufferedImage image) throws PPMEncoderException
image
- the image to be encodedBufferedImage
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |