Method TryDecode
TryDecode(byte[], out DecodedRasterImage?, out string)
Decodes a baseline JPEG image.
public static bool TryDecode(byte[] imageBytes, out DecodedRasterImage? decoded, out string error)
Parameters
imageBytesbyte[]The complete JPEG file bytes.
decodedDecodedRasterImageReceives the decoded image on success.
errorstringReceives the reason on failure.
Returns
- bool
True when the image decoded.
Exceptions
- ArgumentNullException
imageBytesis 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
imageBytesbyte[]The JPEG bytes.
maxPixelslongThe largest
width * heightto admit. Non-positive means unlimited, which is only safe when the payload is trusted.decodedDecodedRasterImageThe decoded image on success.
errorstringThe 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.