PnmEncoder Class
Immutable settings for Netpbm encoding (PBM, PGM, PPM and PAM).
public sealed class PnmEncoder : ImageEncoderRemarks
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
ImageEncoderPnmEncoder
Constructors
| Name | Description |
|---|---|
| PnmEncoder() |
PnmEncoder()
public PnmEncoder()No documentation is available.
Properties
| Name | Description |
|---|---|
| BackgroundColor | 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. |
| Encoding | Gets the raster encoding. Defaults to PnmEncoding.Binary. |
| Format | Gets the format produced by this encoder. |
| PixelLayout | Gets the pixel layout. Defaults to PnmPixelLayout.Auto. |
BackgroundColor
PnmEncoder.csGets 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; }Encoding
PnmEncoder.csGets the raster encoding. Defaults to PnmEncoding.Binary.
public PnmEncoding Encoding { get; init; }Format
PnmEncoder.csPixelLayout
PnmEncoder.csGets the pixel layout. Defaults to PnmPixelLayout.Auto.
public PnmPixelLayout PixelLayout { get; init; }