printImage method
Print the image using print settings set by setPrinterInfo.
Implementation
Future<PrinterStatus> printImage(Image image) async {
var imageBytes = await image.toByteData(format: ImageByteFormat.png);
if (imageBytes == null) {
return PrinterStatus(errorCode: ErrorCode.ERROR_UNSUPPORTED_MEDIA);
}
var outByteArray = Uint8List(imageBytes.lengthInBytes);
for (int i = 0; i < imageBytes.lengthInBytes; i ++) {
outByteArray[i] = imageBytes.getUint8(i);
}
var params = {
"printerId": mPrinterId,
"printInfo": mPrinterInfo.toMap(),
"imageBytes": outByteArray
};
final Map resultMap = await _channel.invokeMethod("printImage", params);
print("Print Result: ${resultMap} ");
PrinterStatus status = PrinterStatus.fromMap(resultMap);
return status;
}