PnmEncoder Class

Immutable settings for Netpbm encoding (PBM, PGM, PPM and PAM).

public sealed class PnmEncoder : ImageEncoder

Remarks

With PnmPixelLayout.Auto the variant follows the pixel format: gray pixel formats are written as a portable graymap (P5, or P2 with PnmEncoding.Plain), pixel formats without alpha as a portable pixmap (P6, or P3), and pixel formats with alpha as a portable arbitrary map (P7, tuple type RGB_ALPHA). MAXVAL is 255 for 8-bit pixel formats and 65,535 for 16-bit ones, so the output is always lossless.

A portable bitmap (P4, or P1 with PnmEncoding.Plain) is only written on request, with PnmPixelLayout.Bitmap. It is lossless too: every pixel must be exactly black or exactly white, and any other pixel is rejected with an UnsupportedImageFeatureException before anything is written. A portable bitmap is read back as PixelFormat.Gray8 with one bit per component.

An encoder never looks at the file extension. Only the save and writer overloads that take a path and no encoder do: they map .pbm to PnmPixelLayout.Bitmap and the other Netpbm extensions to the default settings.

Neither the plain forms nor a portable bitmap store alpha (PAM has no plain form): PnmEncoding.Plain or PnmPixelLayout.Bitmap with a pixel format that has alpha discards alpha and therefore requires PnmEncoder.BackgroundColor.

PNM stores exactly one frame: animated images and images with a poster frame are rejected with an UnsupportedImageFeatureException; use ImageFrame.Save to save one frame explicitly. Several images may be concatenated in one Netpbm file; this version never writes (nor reads) more than one.

Netpbm files store no metadata: an ICC profile, EXIF, XMP, an orientation other than ExifOrientation.TopLeft, a resolution and text entries follow ImageEncoder.MetadataHandling (rejected by default).

Inheritance
ImageEncoder PnmEncoder

Constructors

NameDescription
PnmEncoder()

PnmEncoder()

public PnmEncoder()

No documentation is available.

Properties

NameDescription
BackgroundColorGets the opaque background color non-opaque pixels are composited over when PnmEncoding.Plain or PnmPixelLayout.Bitmap discards alpha, interpreted in the encoded color space of the image (sRGB when untagged), or null to reject non-opaque pixels. Fully opaque images never need it, and a portable arbitrary map (PnmEncoding.Binary with PnmPixelLayout.Auto) ignores it because it stores alpha.
EncodingGets the raster encoding. Defaults to PnmEncoding.Binary.
FormatGets the format produced by this encoder.
PixelLayoutGets the pixel layout. Defaults to PnmPixelLayout.Auto.

BackgroundColor

PnmEncoder.cs

Gets the opaque background color non-opaque pixels are composited over when PnmEncoding.Plain or PnmPixelLayout.Bitmap discards alpha, interpreted in the encoded color space of the image (sRGB when untagged), or null to reject non-opaque pixels. Fully opaque images never need it, and a portable arbitrary map (PnmEncoding.Binary with PnmPixelLayout.Auto) ignores it because it stores alpha.

public Rgba64? BackgroundColor { get; init; }

Property value

Rgba64?

Exceptions

ArgumentException
The color is not fully opaque.

Gets the raster encoding. Defaults to PnmEncoding.Binary.

public PnmEncoding Encoding { get; init; }

Property value

PnmEncoding

Exceptions

ArgumentOutOfRangeException
The value is not a defined PnmEncoding.

Gets the format produced by this encoder.

public override ImageFormat Format { get; }

Property value

ImageFormat

PixelLayout

PnmEncoder.cs

Gets the pixel layout. Defaults to PnmPixelLayout.Auto.

public PnmPixelLayout PixelLayout { get; init; }

Property value

PnmPixelLayout

Exceptions

ArgumentOutOfRangeException
The value is not a defined PnmPixelLayout.