PngCs  1.1.4
A C# library for read/write PNG images
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Properties | List of all members
Hjg.Pngcs.PngWriter Class Reference

Writes a PNG image, line by line. More...

Public Member Functions

 PngWriter (Stream outputStream, ImageInfo imgInfo)
 Constructs a PngWriter from a outputStream, with no filename information
 
 PngWriter (Stream outputStream, ImageInfo imgInfo, String filename)
 Constructs a PngWriter from a outputStream, with optional filename or description
 
void CopyChunksFirst (PngReader reader, int copy_mask)
 
void CopyChunksLast (PngReader reader, int copy_mask)
 
double ComputeCompressionRatio ()
 Computes compressed size/raw size, approximate
 
void End ()
 Finalizes the image creation and closes the file stream.
 
String GetFilename ()
 Filename or description, from the optional constructor argument.
 
void WriteRow (ImageLine imgline, int rownumber)
 this uses the row number from the imageline!
 
void WriteRow (int[] newrow)
 
void WriteRow (int[] newrow, int rown)
 
void WriteRowInt (int[] newrow, int rown)
 Writes a full image row.
 
void WriteRowByte (byte[] newrow, int rown)
 
void WriteRowsInt (int[][] image)
 
void WriteRowsByte (byte[][] image)
 
PngMetadata GetMetadata ()
 
ChunksListForWrite GetChunksList ()
 
void SetFilterType (FilterType filterType)
 Sets internal prediction filter type, or strategy to choose it.
 
bool IsUnpackedMode ()
 
void SetUseUnPackedMode (bool useUnpackedMode)
 

Public Attributes

readonly ImageInfo ImgInfo
 Basic image info, inmutable
 

Protected Member Functions

void encodeRowFromByte (byte[] row)
 
void encodeRowFromInt (int[] row)
 

Protected Attributes

readonly String filename
 filename, or description - merely informative, can be empty
 
byte[] rowb
 raw current row, as array of bytes,counting from 1 (index 0 is reserved for filter type)
 
byte[] rowbprev
 previuos raw row
 
byte[] rowbfilter
 raw current row, after filtered
 

Properties

EDeflateCompressStrategy CompressionStrategy [get, set]
 
int CompLevel [get, set]
 zip compression level (0 - 9)
 
bool ShouldCloseStream [get, set]
 true: closes stream after ending write
 
int IdatMaxSize [get, set]
 Maximum size of IDAT chunks
 
int CurrentChunkGroup [get, set]
 number of chunk group (0-6) last writen, or currently writing
 

Detailed Description

Writes a PNG image, line by line.

Constructor & Destructor Documentation

Hjg.Pngcs.PngWriter.PngWriter ( Stream  outputStream,
ImageInfo  imgInfo 
)

Constructs a PngWriter from a outputStream, with no filename information

Parameters
outputStream
imgInfo
Hjg.Pngcs.PngWriter.PngWriter ( Stream  outputStream,
ImageInfo  imgInfo,
String  filename 
)

Constructs a PngWriter from a outputStream, with optional filename or description

After construction nothing is writen yet. You still can set some parameters (compression, filters) and queue chunks before start writing the pixels.

See also FileHelper.createPngWriter()

Parameters
outputStreamOpened stream for binary writing
imgInfoBasic image parameters
filenameOptional, can be the filename or a description.

Member Function Documentation

void Hjg.Pngcs.PngWriter.encodeRowFromByte ( byte[]  row)
protected
void Hjg.Pngcs.PngWriter.encodeRowFromInt ( int[]  row)
protected
void Hjg.Pngcs.PngWriter.CopyChunksFirst ( PngReader  reader,
int  copy_mask 
)
void Hjg.Pngcs.PngWriter.CopyChunksLast ( PngReader  reader,
int  copy_mask 
)
double Hjg.Pngcs.PngWriter.ComputeCompressionRatio ( )

Computes compressed size/raw size, approximate

Actually: compressed size = total size of IDAT data , raw size = uncompressed pixel bytes = rows * (bytesPerRow + 1)

Returns
void Hjg.Pngcs.PngWriter.End ( )

Finalizes the image creation and closes the file stream.

This MUST be called after writing the lines.

String Hjg.Pngcs.PngWriter.GetFilename ( )

Filename or description, from the optional constructor argument.

Returns
void Hjg.Pngcs.PngWriter.WriteRow ( ImageLine  imgline,
int  rownumber 
)

this uses the row number from the imageline!

void Hjg.Pngcs.PngWriter.WriteRow ( int[]  newrow)
void Hjg.Pngcs.PngWriter.WriteRow ( int[]  newrow,
int  rown 
)
void Hjg.Pngcs.PngWriter.WriteRowInt ( int[]  newrow,
int  rown 
)

Writes a full image row.

This must be called sequentially from n=0 to n=rows-1 One integer per sample , in the natural order: R G B R G B ... (or R G B A R G B A... if has alpha) The values should be between 0 and 255 for 8 bitspc images, and between 0- 65535 form 16 bitspc images (this applies also to the alpha channel if present) The array can be reused.

Parameters
newrowArray of pixel values
rownNumber of row, from 0 (top) to rows-1 (bottom)
void Hjg.Pngcs.PngWriter.WriteRowByte ( byte[]  newrow,
int  rown 
)
void Hjg.Pngcs.PngWriter.WriteRowsInt ( int  image[][])

Writes all the pixels, calling writeRowInt() for each image row

void Hjg.Pngcs.PngWriter.WriteRowsByte ( byte  image[][])

Writes all the pixels, calling writeRowByte() for each image row

PngMetadata Hjg.Pngcs.PngWriter.GetMetadata ( )
ChunksListForWrite Hjg.Pngcs.PngWriter.GetChunksList ( )
void Hjg.Pngcs.PngWriter.SetFilterType ( FilterType  filterType)

Sets internal prediction filter type, or strategy to choose it.

This must be called just after constructor, before starting writing.

Recommended values: DEFAULT (default) or AGGRESIVE

Parameters
filterTypeOne of the five prediction types or strategy to choose it
bool Hjg.Pngcs.PngWriter.IsUnpackedMode ( )
void Hjg.Pngcs.PngWriter.SetUseUnPackedMode ( bool  useUnpackedMode)

Member Data Documentation

readonly ImageInfo Hjg.Pngcs.PngWriter.ImgInfo

Basic image info, inmutable

readonly String Hjg.Pngcs.PngWriter.filename
protected

filename, or description - merely informative, can be empty

byte [] Hjg.Pngcs.PngWriter.rowb
protected

raw current row, as array of bytes,counting from 1 (index 0 is reserved for filter type)

byte [] Hjg.Pngcs.PngWriter.rowbprev
protected

previuos raw row

byte [] Hjg.Pngcs.PngWriter.rowbfilter
protected

raw current row, after filtered

Property Documentation

EDeflateCompressStrategy Hjg.Pngcs.PngWriter.CompressionStrategy
getset

Deflate algortithm compression strategy

int Hjg.Pngcs.PngWriter.CompLevel
getset

zip compression level (0 - 9)

default:6

9 is the maximum compression

bool Hjg.Pngcs.PngWriter.ShouldCloseStream
getset

true: closes stream after ending write

int Hjg.Pngcs.PngWriter.IdatMaxSize
getset

Maximum size of IDAT chunks

0=use default (PngIDatChunkOutputStream 32768)

int Hjg.Pngcs.PngWriter.CurrentChunkGroup
getset

number of chunk group (0-6) last writen, or currently writing

see ChunksList.CHUNK_GROUP_NNN