Package sim.util.media
Class PNGEncoder
java.lang.Object
sim.util.media.PNGEncoder
PNGEncoder takes a Java Image object and creates a byte string which can be saved as a PNG file.
The Image is presumed to use the DirectColorModel.
This code is taken, with permission, from J. David Eisenberg (david@catcode.com), and is distributed under the Artistic License.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
Constants for filtersstatic final int
static final int
-
Constructor Summary
ConstructorDescriptionClass constructorPNGEncoder
(Image image) Class constructor specifying Image to encode, with no alpha channel encoding.PNGEncoder
(Image image, boolean encodeAlpha) Class constructor specifying Image to encode, and whether to encode alpha.PNGEncoder
(Image image, boolean encodeAlpha, int whichFilter) Class constructor specifying Image to encode, whether to encode alpha, and filter to use.PNGEncoder
(Image image, boolean encodeAlpha, int whichFilter, int compLevel) Class constructor specifying Image source to encode, whether to encode alpha, filter to use, and compression level. -
Method Summary
Modifier and TypeMethodDescriptionint
Retrieve compression levelboolean
Retrieve alpha encoding status.int
Retrieve filtering schemebyte[]
Creates an array of bytes that is the PNG equivalent of the current image, specifying whether to encode alpha or not.void
setCompressionLevel
(int level) Set the compression level to usevoid
setEncodeAlpha
(boolean encodeAlpha) Set the alpha encoding on or off.void
setFilter
(int whichFilter) Set the filter to usevoid
Set the image to be encoded
-
Field Details
-
FILTER_NONE
public static final int FILTER_NONEConstants for filters- See Also:
-
FILTER_SUB
public static final int FILTER_SUB- See Also:
-
FILTER_UP
public static final int FILTER_UP- See Also:
-
-
Constructor Details
-
PNGEncoder
public PNGEncoder()Class constructor -
PNGEncoder
Class constructor specifying Image to encode, with no alpha channel encoding.- Parameters:
image
- A Java Image object which uses the DirectColorModel- See Also:
-
PNGEncoder
Class constructor specifying Image to encode, and whether to encode alpha.- Parameters:
image
- A Java Image object which uses the DirectColorModelencodeAlpha
- Encode the alpha channel? false=no; true=yes- See Also:
-
PNGEncoder
Class constructor specifying Image to encode, whether to encode alpha, and filter to use.- Parameters:
image
- A Java Image object which uses the DirectColorModelencodeAlpha
- Encode the alpha channel? false=no; true=yeswhichFilter
- 0=none, 1=sub, 2=up- See Also:
-
PNGEncoder
Class constructor specifying Image source to encode, whether to encode alpha, filter to use, and compression level.- Parameters:
image
- A Java Image objectencodeAlpha
- Encode the alpha channel? false=no; true=yeswhichFilter
- 0=none, 1=sub, 2=upcompLevel
- 0..9- See Also:
-
-
Method Details
-
setImage
Set the image to be encoded- Parameters:
image
- A Java Image object which uses the DirectColorModel- See Also:
-
pngEncode
public byte[] pngEncode()Creates an array of bytes that is the PNG equivalent of the current image, specifying whether to encode alpha or not.- Parameters:
encodeAlpha
- boolean false=no alpha, true=encode alpha- Returns:
- an array of bytes, or null if there was a problem
-
setEncodeAlpha
public void setEncodeAlpha(boolean encodeAlpha) Set the alpha encoding on or off.- Parameters:
encodeAlpha
- false=no, true=yes
-
getEncodeAlpha
public boolean getEncodeAlpha()Retrieve alpha encoding status.- Returns:
- boolean false=no, true=yes
-
setFilter
public void setFilter(int whichFilter) Set the filter to use- Parameters:
whichFilter
- from constant list
-
getFilter
public int getFilter()Retrieve filtering scheme- Returns:
- int (see constant list)
-
setCompressionLevel
public void setCompressionLevel(int level) Set the compression level to use- Parameters:
level
- 0 through 9
-
getCompressionLevel
public int getCompressionLevel()Retrieve compression level- Returns:
- int in range 0-9
-