Table of Contents

Method TryDecode

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

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

Decodes a baseline JPEG image.

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

Parameters

imageBytes byte[]

The complete JPEG 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 JPEG, 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 JPEG 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 frame header states the image's size in about twenty bytes and the decoder then allocates a sample plane per component from it, so the budget is checked against that header before any plane exists. The overload without it applies DefaultMaxImagePixels rather than no budget at all.