imageFromBytes method

PrintBuilder imageFromBytes(
  1. Uint8List imageBytes, {
  2. AlignPos align = AlignPos.center,
  3. int? maxWidth,
})

Print image from bytes

Implementation

PrintBuilder imageFromBytes(
    Uint8List imageBytes, {
      AlignPos align = AlignPos.center,
      int? maxWidth,
    }) {
  // Set alignment
  switch (align) {
    case AlignPos.left:
      _bytes.addAll(ESCPOSCommands.alignLeft);
      break;
    case AlignPos.center:
      _bytes.addAll(ESCPOSCommands.alignCenter);
      break;
    case AlignPos.right:
      _bytes.addAll(ESCPOSCommands.alignRight);
      break;
  }

  // Process image and add to bytes
  final processedImage = ImageProcessor.processImageForPrinting(
    imageBytes,
    paperSize: paperSize,
    maxWidth: maxWidth,
  );

  _bytes.addAll(processedImage);

  // Reset alignment
  _bytes.addAll(ESCPOSCommands.alignLeft);

  return this;
}