MemoryImage constructor

MemoryImage(
  1. Uint8List bytes, {
  2. PdfImageOrientation? orientation,
  3. double? dpi,
})

Implementation

factory MemoryImage(
  Uint8List bytes, {
  PdfImageOrientation? orientation,
  double? dpi,
}) {
  final decoder = im.findDecoderForData(bytes);
  if (decoder == null) {
    throw Exception('Unable to guess the image type ${bytes.length} bytes');
  }

  if (decoder is im.JpegDecoder) {
    final info = PdfJpegInfo(bytes);

    return MemoryImage._(
      bytes,
      info.width,
      info.height,
      orientation ?? info.orientation,
      dpi,
    );
  }

  final info = decoder.startDecode(bytes);

  if (info == null) {
    throw Exception('Unable decode the image');
  }

  return MemoryImage._(
    bytes,
    info.width,
    info.height,
    orientation ?? PdfImageOrientation.topLeft,
    dpi,
  );
}