Table of Contents

Class PngWriterOptions

Namespace
Egami.Formats.Png
Assembly
Egami.dll

Options for writing PNG. The defaults keep every pixel exactly, in the color type that matches the raster's pixel type.

public sealed class PngWriterOptions : WriterOptions
Inheritance
PngWriterOptions
Inherited Members

Examples

// Force a palette, choose a filter and a zlib strategy, and keep a private chunk.
((PngDetails)image.Metadata.FormatDetails!).OtherChunks.Add(
    new PngChunk("prVt", "hello"u8.ToArray(), PngChunkPosition.AfterImageData));
image.Save("duck-palette.png", new PngWriterOptions
{
    ColorType = PngColorType.Palette,
    Filter = PngFilterMode.Paeth,
    CompressionStrategy = PngCompressionStrategy.Filtered,
});

Properties

BitDepth

Gets the bit depth to write, or null for the color type's natural depth. Lower depths than the image holds round each value to the nearest one the depth can store.

public int? BitDepth { get; init; }

Property Value

int?

Exceptions

ArgumentOutOfRangeException

The value is not 1, 2, 4, 8 or 16.

ColorType

Gets the color type to write, or null to follow the pixel type (or Reduce). A palette for an image with more colors than the bit depth holds is built as Palette says.

public PngColorType? ColorType { get; init; }

Property Value

PngColorType?

CompressionLevel

Gets the zlib compression level, 0 (none, fastest) to 9 (smallest). Defaults to 5, which on photos compressed over twice as fast as level 6 for files about 5% larger.

public int CompressionLevel { get; init; }

Property Value

int

Exceptions

ArgumentOutOfRangeException

The value is outside 0 to 9.

CompressionStrategy

Gets the Deflate strategy. Defaults to Auto.

public PngCompressionStrategy CompressionStrategy { get; init; }

Property Value

PngCompressionStrategy

Default

Gets the default options.

public static PngWriterOptions Default { get; }

Property Value

PngWriterOptions

Filter

Gets how rows are filtered. Defaults to Adaptive.

public PngFilterMode Filter { get; init; }

Property Value

PngFilterMode

FirstFrameOnly

Gets whether only the first frame is written. Defaults to false: a raster with more than one frame is written as an APNG, which viewers without APNG support show as its first frame.

public bool FirstFrameOnly { get; init; }

Property Value

bool

FrameCount

Gets how many frames an APNG written with WriteFrame(Raster<TPixel>, FrameMetadata?) will have, or null to count them. APNG stores the count before the first frame: a seekable stream has it filled in at Complete(), but a stream that cannot seek needs it here. Save counts the raster's frames and ignores this.

public int? FrameCount { get; init; }

Property Value

int?

Exceptions

ArgumentOutOfRangeException

The value is less than 1.

Interlace

Gets whether to write the image Adam7 interlaced, so a viewer can show a coarse version before the whole file has arrived. Defaults to false, and an interlaced source is written non-interlaced unless this is set: interlaced files are usually larger and slower to write and read. Every color type, bit depth, palette and APNG frame can be interlaced; a streamed encode holds the whole image until the last row, since the first pass needs rows from the whole height.

public bool Interlace { get; init; }

Property Value

bool

Palette

Gets how a palette is built when ColorType is Palette and the image has more colors than fit; partial alpha is kept in the palette. Defaults to Default. Images whose colors fit keep them exactly, and Reduce never quantizes.

public PaletteOptions Palette { get; init; }

Property Value

PaletteOptions

ParallelCompression

Gets whether to compress large images on several threads, up to MaxParallelism. The image data is cut into fixed bands of about 1 MiB, each compressed on its own, so the file is the same whatever the number of threads, and usually under 1% larger than with this off. Only images with more than 4 MiB of image data are split; smaller ones are written as when this is off. Defaults to false.

public bool ParallelCompression { get; init; }

Property Value

bool

Reduce

Gets a value indicating whether to scan the image first and write the smallest exact form: no alpha when every pixel is opaque, gray when every pixel is gray, a palette when there are at most 256 colors, and the lowest bit depth that keeps every value. The file decodes to exactly the same pixels. Ignored when ColorType is set. Defaults to false.

public bool Reduce { get; init; }

Property Value

bool