Table of Contents

Method TryDecode

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

TryDecode(byte[], out DecodedRasterImage?, out string)

Decodes a PNG image.

public static bool TryDecode(byte[] imageBytes, out DecodedRasterImage? decoded, out string error)

Parameters

imageBytes byte[]

The complete PNG file bytes.

decoded DecodedRasterImage

Receives the decoded image on success.

error string

Receives the reason on failure.

Returns

bool

True when the image decoded.

Exceptions

ArgumentNullException

imageBytes is null.

TryDecode(byte[], long, out DecodedRasterImage?, out string)

Decodes a PNG, refusing an image whose declared dimensions pass a pixel budget.

public static bool TryDecode(byte[] imageBytes, long maxPixels, out DecodedRasterImage? decoded, out string error)

Parameters

imageBytes byte[]

The PNG bytes.

maxPixels long

The largest width * height to admit. Non-positive means unlimited, which is only safe when the payload is trusted.

decoded DecodedRasterImage

The decoded image on success.

error string

The failure description.

Returns

bool

True when the image decoded.

Remarks

The budget is checked against the header before a byte is inflated, because both the buffer sizes and the inflate ceiling are derived from those dimensions. The overload without it applies DefaultMaxImagePixels rather than no budget at all: an image decoder reached by untrusted input should not have an unbounded default, and a caller that means unbounded can now say so explicitly.