toByteData method Null safety

Future<ByteData?> toByteData(
  1. {ImageByteFormat format = ImageByteFormat.rawRgba}
)

Converts the Image object into a byte array.

The format argument specifies the format in which the bytes will be returned.

Returns a future that completes with the binary image data or an error if encoding fails.

Implementation

// We do not expect to add more encoding formats to the ImageByteFormat enum,
// considering the binary size of the engine after LTO optimization. You can
// use the third-party pure dart image library to encode other formats.
// See: https://github.com/flutter/flutter/issues/16635 for more details.
Future<ByteData?> toByteData({ImageByteFormat format = ImageByteFormat.rawRgba}) {
  assert(!_disposed && !_image._disposed);
  return _image.toByteData(format: format);
}