decodeOrNull

Decodes a PNG or JPEG file held in bytes into a new image, or returns null when bytes is empty, is not a PNG or JPEG file, or is corrupt. Images with fewer channels are expanded to RGBA, with opaque alpha when the file has none.

bytes is only read during the call and never retained, so the caller may reuse it.

Samples

assertPrints(Image.decodeOrNull(byteArrayOf(1, 2, 3)), "null")