image method

void image(
  1. Image subImage, {
  2. int? width,
  3. int? height,
  4. PrintAlign align = PrintAlign.left,
})

Draw image (resized)

Implementation

void image(
  img.Image subImage, {
  int? width,
  int? height,
  PrintAlign align = PrintAlign.left,
}) {
  final resized = copyResize(
    subImage,
    width: width ?? subImage.width,
    height: height ?? subImage.height,
  );

  int posX;
  final posY = runningHeight;

  if (align == PrintAlign.center) {
    posX = ((paperSize.width - resized.width) / 2).round();
  } else if (align == PrintAlign.right) {
    posX = paperSize.width - resized.width - margin.right;
  } else {
    posX = margin.left;
  }

  for (int sy = 0; sy < resized.height; sy++) {
    for (int sx = 0; sx < resized.width; sx++) {
      final pixel = resized.getPixel(sx, sy).current;
      utilImage.setPixel(posX + sx, posY + sy, pixel);
    }
  }
  runningHeight += (resized.height + 10);
}