PdfImage.jpeg constructor

PdfImage.jpeg(
  1. PdfDocument pdfDocument, {
  2. required Uint8List image,
  3. PdfImageOrientation? orientation,
})

Create an image from a jpeg file

Implementation

factory PdfImage.jpeg(
  PdfDocument pdfDocument, {
  required Uint8List image,
  PdfImageOrientation? orientation,
}) {
  final info = PdfJpegInfo(image);
  final im = PdfImage._(
    pdfDocument,
    info.width!,
    info.height,
    orientation ?? info.orientation,
  );

  assert(() {
    im.startStopwatch();
    im.debugFill('Jpeg Image ${info.width}x${info.height}');
    return true;
  }());
  im.params[PdfNameTokens.bitsPerComponent] = const PdfNum(8);
  im.params[PdfNameTokens.name] = PdfName(im.name);
  im.params[PdfNameTokens.intent] = const PdfName(PdfNameTokens.relativecolorimetric);
  im.params[PdfNameTokens.filter] = const PdfName(PdfNameTokens.dctDecode);

  if (info.isRGB) {
    im.params[PdfNameTokens.colorSpace] = const PdfName(PdfNameTokens.deviceRgb);
  } else {
    im.params[PdfNameTokens.colorSpace] = const PdfName(PdfNameTokens.deviceGray);
  }

  im.buf.putBytes(image);
  assert(() {
    im.stopStopwatch();
    return true;
  }());
  return im;
}