Image.fromBytes constructor Null safety

Image.fromBytes(
  1. int width,
  2. int height,
  3. List<int> bytes,
  4. {ExifData? exif,
  5. ICCProfileData? iccp,
  6. Format format = Format.rgba,
  7. Channels channels = Channels.rgba}
)

Create an image from raw data in bytes.

format defines the order of color channels in bytes. An HTML canvas element stores colors in Format.rgba format; a Flutter Image object stores colors in Format.rgba format. The length of bytes should be (width * height) * format-byte-count, where format-byte-count is 1, 3, or 4 depending on the number of channels in the format (luminance, rgb, rgba, etc).

The native format of an image is Format.rgba. If another format is specified, the input data will be converted to rgba to store in the Image.

For example, given an Html Canvas, you could create an image: var bytes = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height).data; var image = Image.fromBytes(canvas.width, canvas.height, bytes, format: Format.rgba);

Implementation

Image.fromBytes(this.width, this.height, List<int> bytes,
    {ExifData? exif,
    ICCProfileData? iccp,
    Format format = Format.rgba,
    this.channels = Channels.rgba})
    : data = _convertData(width, height, bytes, format),
      exif = ExifData.from(exif),
      iccProfile = iccp;