Method TryDecode
TryDecode(byte[], out DecodedRasterImage?, out string)
Decodes a PNG image.
public static bool TryDecode(byte[] imageBytes, out DecodedRasterImage? decoded, out string error)
Parameters
imageBytesbyte[]The complete PNG 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 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
imageBytesbyte[]The PNG 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 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.