|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectewe.fx.PNGEncoder
This class can be used to save a PNG encoded image. You can use a single method, writeImage() to save an existing image to a stream. You can also use it to save more data by calling the individual methods in the correct sequence.
In general you will call one of the start() methods, then writeHeader() to write the important information. You can then call the writeChunk() methods to write any extra chunks you want. Then call startDataChunk() to begin sending data. You can then call writeScanLine() to send out as many image scan lines as you want. Then call endDataChunk() to end and write a data chunk.
When you have written all the data chunks you want (you can send a single data chunk if you wish - but this takes up more memory) you then call writeEnd() to write the end of the PNG image and then closeOutput() if you want to close the stream as well.
| Field Summary | |
protected ByteArrayOutputStream |
curStream
|
protected DeflaterOutputStream |
dos
|
protected OutputStream |
output
|
protected static int[] |
signature
|
static int |
TYPE_GRAY_SCALE_SCALE
|
static int |
TYPE_GRAY_SCALE_SCALE_ALPHA
|
static int |
TYPE_PALETTE
|
static int |
TYPE_TRUE_COLOR
|
static int |
TYPE_TRUE_COLOR_ALPHA
|
| Constructor Summary | |
PNGEncoder()
|
|
| Method Summary | |
void |
closeOutput()
Closes the underlying output stream. |
void |
end()
This ends the current data chunk, writes the end and closes the output. |
void |
endDataChunk()
Closes the current data chunk and writes the compressed data for the current chunk. |
void |
start(Stream out,
int width,
int height,
boolean useAlpha)
This starts a true color PNG. |
void |
start(Stream out,
int width,
int height,
int bitDepth,
int type)
This writes the signature and header, starts the data chunks and is ready for scan lines. |
void |
startDataChunk()
This starts a chunk of scan line data using the default compression. |
void |
startDataChunk(int compressionLevel)
This starts a chunk of scan line data using the specified compression leve. |
void |
startImage(Stream out,
IImage image)
Start the PNG file in preparation for output of an image. |
void |
startImage(Stream out,
IImage image,
boolean useAlpha)
Start the PNG file in preparation for output of an image. |
void |
startOutput(OutputStream out)
|
void |
startOutput(Stream os)
This is the very basic start method. |
protected boolean |
usingAlpha()
|
protected void |
writeByte(int value,
OutputStream out,
CRC32 crc)
|
void |
writeChunk(String value,
byte[] bytes)
Write a PNG chunk to the image. |
void |
writeChunk(String value,
byte[] bytes,
int offset,
int length)
Write a PNG chunk to the image. |
void |
writeEnd()
This writes the end chunk marking the end of the PNG file. |
void |
writeHeader(int width,
int height,
int bitDepth,
int colorType)
This writes the IHDR chunk, always using standard Deflator compression. |
void |
writeImage(IImage image)
Use this after startImage() to write the actual image data. |
void |
writeImage(Stream out,
IImage image)
Write out an entire Image to the stream as a complete PNG image, as a TRUE_COLOR or TRUE_COLOR_ALPHA image. |
void |
writeImage(Stream out,
IImage image,
boolean useAlpha)
This method will write out an entire image to the stream as a complete PNG image, as a TRUE_COLOR or TRUE_COLOR_ALPHA image. |
protected void |
writeInt(int value,
OutputStream out,
CRC32 crc)
|
void |
writeScanLine(byte[] line,
int offset,
int length)
Use this to write scan line data. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, toString |
| Field Detail |
public static final int TYPE_GRAY_SCALE_SCALE
public static final int TYPE_PALETTE
public static final int TYPE_GRAY_SCALE_SCALE_ALPHA
public static final int TYPE_TRUE_COLOR
public static final int TYPE_TRUE_COLOR_ALPHA
protected OutputStream output
protected static int[] signature
protected ByteArrayOutputStream curStream
protected DeflaterOutputStream dos
| Constructor Detail |
public PNGEncoder()
| Method Detail |
protected boolean usingAlpha()
protected void writeInt(int value,
OutputStream out,
CRC32 crc)
throws IOException
IOException
protected void writeByte(int value,
OutputStream out,
CRC32 crc)
throws IOException
IOException
public void writeChunk(String value,
byte[] bytes)
throws IOException
value - The 4-character code for the chunk.bytes - The bytes in the chunk to write (not including the length). This can be null, indicating no data.
IOException - if an error occurs writing to the Stream.
public void writeChunk(String value,
byte[] bytes,
int offset,
int length)
throws IOException
value - The 4-character code for the chunk.bytes - The bytes in the chunk to write (not including the length).
This can be null, indicating no data, in which case length must also be 0.offset - The start location in the bytes.length - The number of bytes.
IOException - if an error occurs writing to the Stream.
public void startOutput(Stream os)
throws IOException
IOException
public void startOutput(OutputStream out)
throws IOException
IOException
public void writeHeader(int width,
int height,
int bitDepth,
int colorType)
throws IOException
IOException
public void writeEnd()
throws IOException
IOException
public void startDataChunk()
throws IOException
IOException
public void startDataChunk(int compressionLevel)
throws IOException
IOException
public void writeScanLine(byte[] line,
int offset,
int length)
throws IOException
IOException
public void endDataChunk()
throws IOException
IOException
public void closeOutput()
throws IOException
IOException
public void start(Stream out,
int width,
int height,
boolean useAlpha)
throws IOException
IOException
public void start(Stream out,
int width,
int height,
int bitDepth,
int type)
throws IOException
IOException
public void end()
throws IOException
IOException
public void startImage(Stream out,
IImage image)
throws IOException,
IllegalArgumentException
out - The output Stream. To write to a byte array use a new MemoryFile as the Stream.image - The image to write.
IOException - If there is an error writing the data.
IllegalArgumentException - If there is an error with the image.
public void startImage(Stream out,
IImage image,
boolean useAlpha)
throws IOException,
IllegalArgumentException
out - The output Stream. To write to a byte array use a new MemoryFile as the Stream.image - The image to write.
IOException - If there is an error writing the data.
IllegalArgumentException - If there is an error with the image.
public void writeImage(IImage image)
throws IOException,
IllegalArgumentException
image - The image to write.
IOException - If there is an error writing the data.
IllegalArgumentException - If there is an error with the image.
public void writeImage(Stream out,
IImage image)
throws IOException,
IllegalArgumentException
out - The output Stream. To write to a byte array use a new MemoryFile as the Stream.image - The image to write.
IOException - If there is an error writing the data.
IllegalArgumentException - If there is an error with the image.
public void writeImage(Stream out,
IImage image,
boolean useAlpha)
throws IOException,
IllegalArgumentException
out - The output Stream. To write to a byte array use a new MemoryFile as the Stream.image - The image to write.
IOException - If there is an error writing the data.
IllegalArgumentException - If there is an error with the image.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||