|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.objectplanet.image.PngEncoder
public class PngEncoder
This PngEncoder class converts a java image to a PNG image and writes it to a specified output stream. It is compatible with JDK 1.1 and later.
The encoder supports 8 bit indexed images with 256 colors, 16 bit grayscale images and 24 bit RGB images. Full alpha channel is supported for truecolor and grayscale images while indexed images can only contain fully opaque or fully transparent pixels. Indexed images are generally smaller in size than truecolor and grayscale images.
FileOutputStream out = new FileOutputStream("image.png"); PngEncoder encoder = new PngEncoder(); encoder.encode(image,out);Version: 2.0
Field Summary | |
---|---|
static int |
BEST_COMPRESSION
The best compression level. |
static int |
BEST_SPEED
The compression level with the best speed. |
static int |
COLOR_GRAYSCALE
Encode the image as 16bit grayscale image. |
static int |
COLOR_GRAYSCALE_ALPHA
Encode the image as 16bit grayscale image with alpha. |
static int |
COLOR_INDEXED
Encode the image as a palette indexed image with maximum 256 colors. |
static int |
COLOR_INDEXED_ALPHA
Encode the image as a palette indexed image with maximum 256 colors. |
static int |
COLOR_TRUECOLOR
Encode the image as 24bit truecolor RGB image with 16,7 million colors. |
static int |
COLOR_TRUECOLOR_ALPHA
Encode the image as 24bit truecolor image with alpha. |
static int |
DEFAULT_COMPRESSION
The default compression level. |
static int |
INDEXED_COLORS_AUTO
The PngEncoder checks automatically if it should use original colors or convert to the pre-set palette. |
static int |
INDEXED_COLORS_CONVERT
The original colors are used for the indexed PNG output. |
static int |
INDEXED_COLORS_ORIGINAL
The original colors are converted to the pre-set palette. |
Constructor Summary | |
---|---|
PngEncoder()
Creates a new PngEncoder for truecolor images and default compression. |
|
PngEncoder(int colorType)
Creates a new PngEncoder with the specified color type and default compression. |
|
PngEncoder(int colorType,
int compression)
Creates a new PngEncoder with the specified color type and compression. |
Method Summary | |
---|---|
void |
encode(java.awt.Image image,
java.io.OutputStream out)
Encodes an image to an output stream as a PNG image. |
int |
getColorType()
Gets the current image type. |
int |
getIndexedColorMode()
Gets current mode of processing original image to indexed PNG. |
static java.lang.String |
getVersion()
Gets the version number. |
static void |
main(java.lang.String[] argv)
Prints out the version number. |
void |
setColorType(int colorType)
Sets the encoded image type. |
void |
setCompression(int level)
Sets the image compression level. |
void |
setIndexedColorMode(int mode)
Sets mode to process the original image to indexed PNG output. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int BEST_COMPRESSION
public static final int BEST_SPEED
public static final int COLOR_GRAYSCALE
public static final int COLOR_GRAYSCALE_ALPHA
public static final int COLOR_INDEXED
public static final int COLOR_INDEXED_ALPHA
public static final int COLOR_TRUECOLOR
public static final int COLOR_TRUECOLOR_ALPHA
public static final int DEFAULT_COMPRESSION
public static final int INDEXED_COLORS_AUTO
public static final int INDEXED_COLORS_CONVERT
public static final int INDEXED_COLORS_ORIGINAL
Constructor Detail |
---|
public PngEncoder()
public PngEncoder(int colorType)
colorType
- COLOR_TRUECOLOR, COLOR_INDEXED or COLOR_GRAYSCALE.
java.lang.IllegalArgumentException
- If the color type is invalid.public PngEncoder(int colorType, int compression)
colorType
- COLOR_TRUECOLOR, COLOR_INDEXED, COLOR_GRAYSCALE, COLOR_TRUECOLOR_ALPHA, COLOR_INDEXED_ALPHA, COLOR_GRAYSCALE_ALPHA.compression
- The compression level (0-9 or DEFAULT_COMPRESSION, BEST_SPEED, BEST_COMPRESSION).Method Detail |
---|
public void encode(java.awt.Image image, java.io.OutputStream out) throws java.io.IOException
image
- the buffered image to encode.out
- the output stream to write the encoded data to.
java.io.IOException
public int getColorType()
public int getIndexedColorMode()
public static java.lang.String getVersion()
public static void main(java.lang.String[] argv)
public void setColorType(int colorType)
colorType
- COLOR_INDEXED, COLOR_TRUECOLOR or COLOR_GRAYSCALE.
java.lang.IllegalArgumentException
- If the color type is invalid.public void setCompression(int level)
level
- 0-9 or DEFAULT_COMPRESSION, BEST_SPEED, or BEST_COMPRESSION.
java.lang.IllegalArgumentException
- If the compression level is invalid.public void setIndexedColorMode(int mode)
mode
- One of the following: INDEXED_COLORS_AUTO, INDEXED_COLORS_ORIGINAL, INDEXED_COLORS_CONVERT.
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |