Table of Contents

Class RasterImageHeader

Namespace
DocWright.Core.Imaging
Assembly
DocWright.Core.dll

Reads an encoded image's pixel dimensions from its header, without decoding its pixels.

public static class RasterImageHeader
Inheritance
RasterImageHeader
Inherited Members

Remarks

A caller that needs an image's natural size — how large it draws when nothing states a size — needs two integers out of a header, not a decoded surface. Decoding to learn them costs the whole image: a 40-megapixel JPEG is a tenth of a second and 160 MB to answer a question its first sixteen bytes contain.

This reads the header only, so it is bounded by construction: it walks a fixed number of fields, never allocates from a declared length, and never decompresses anything. A truncated, hostile or unknown file returns false rather than throwing — the size is not knowable, which is a fact about the input and not an error condition.

PNG and JPEG only, which is what PngImageDecoder and JpegImageDecoder can go on to draw. A format whose size could be read but whose pixels could not is worse than no answer, because the caller would size a box for an image that never appears.

Fields

AssumedPixelsPerInch

The resolution an image is assumed to have been authored at when its size is converted to a physical measure: 96 pixels per inch.

Methods

TryReadSize(byte[]?, out int, out int)

Reads an image's pixel dimensions from its header.