printImage method
Future<void>
printImage(
{ - required Image image,
- PaperSize paperSize = PaperSize.mm58,
- void progress(
- int total,
- int progress
)?,
})
Implementation
Future<void> printImage({
required img.Image image,
PaperSize paperSize = PaperSize.mm58,
void Function(int total, int progress)? progress,
}) async {
img.Image src;
final dotsPerLine = paperSize.width;
// make sure image not bigger than printable area
if (image.width > dotsPerLine) {
double ratio = dotsPerLine / image.width;
int height = (image.height * ratio).ceil();
src = img.copyResize(
image,
width: dotsPerLine,
height: height,
);
} else {
src = image;
}
final profile = await CapabilityProfile.load();
final generator = Generator(paperSize, profile);
final data = generator.image(src);
await printBytes(
bytes: Uint8List.fromList(data),
progress: progress,
);
}