toByteData method

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.

Using ImageByteFormat.rawRgba on an image in the color space ColorSpace.extendedSRGB will result in the gamut being squished to fit into the sRGB gamut, resulting in the loss of wide-gamut colors.

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


// 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: for more details.
Future<ByteData?> toByteData({ImageByteFormat format = ImageByteFormat.rawRgba}) {
  assert(!_disposed && !_image._disposed);
  return _image.toByteData(format: format);