printOptimizedImage static method
Optimize an image for thermal printing and print it.
Adjusts an image for better quality on thermal printers.
imagePath: Path to the image filewidth: Width to resize the image (0 = printer default)alignment: Image alignment (left, center, right)threshold: Threshold for binarization (0-255)dither: Whether to apply dithering
Returns true if printing was successful.
Implementation
static Future<bool> printOptimizedImage(
String imagePath, {
int width = 0,
Alignment alignment = Alignment.centerLeft,
int threshold = 128,
bool dither = true,
}) async {
try {
// Load the image
final File imageFile = File(imagePath);
final Uint8List imageBytes = await imageFile.readAsBytes();
// Optimize the image for thermal printing
final optimizedBytes = await ImageUtils.optimizeForThermalPrinting(
imageBytes,
threshold: threshold,
dither: dither,
);
// Print the optimized image
return await printImageBytes(
optimizedBytes,
width: width,
alignment: alignment,
);
} catch (e) {
print('Error printing optimized image: $e');
return false;
}
}