decode method

  1. @override
Image? decode(
  1. Uint8List bytes, {
  2. int? frame,
})
override

Decode the file and extract a single image from it. If the file is animated, the specified frame will be decoded. If there was a problem decoding the file, null is returned.

Implementation

@override
Image? decode(Uint8List bytes, {int? frame}) {
  if (startDecode(bytes) == null) {
    return null;
  }

  final len = numFrames();
  if (len == 1 || frame != null) {
    return decodeFrame(frame ?? 0);
  }

  Image? firstImage;
  for (var i = 0; i < len; ++i) {
    final frame = decodeFrame(i);
    if (frame == null) {
      continue;
    }
    if (firstImage == null) {
      firstImage = frame;
      frame.frameType = FrameType.page;
    } else {
      firstImage.addFrame(frame);
    }
  }

  return firstImage;
}