kakzaki / blue_thermal_printer

Working with thermal printer via bluetooth (Flutter)
MIT License
164 stars 205 forks source link

Can not print an image #174

Closed 15ground closed 1 year ago

15ground commented 1 year ago

I want to print an image but it printed very much weird chars. Im using printer Zebra MZ320. Please help me to find solutions Example code: sample() async { ///image from Asset ByteData bytesAsset = await rootBundle.load("assets/images/yourlogo.png"); Uint8List imageBytesFromAsset = bytesAsset.buffer .asUint8List(bytesAsset.offsetInBytes, bytesAsset.lengthInBytes);

///image from Network
var response = await http.get(Uri.parse(
    "https://raw.githubusercontent.com/kakzaki/blue_thermal_printer/master/example/assets/images/yourlogo.png"));
Uint8List bytesNetwork = response.bodyBytes;
Uint8List imageBytesFromNetwork = bytesNetwork.buffer
    .asUint8List(bytesNetwork.offsetInBytes, bytesNetwork.lengthInBytes);

bluetooth.isConnected.then((isConnected) {
  if (isConnected == true) {
    bluetooth.printNewLine();
    bluetooth.printImageBytes(imageBytesFromAsset); //image from Asset
    bluetooth.printNewLine();
    bluetooth.printImageBytes(imageBytesFromNetwork); //image from Network

    bluetooth
        .paperCut(); //some printer not supported (sometime making image not centered)
    bluetooth.drawerPin2(); // or you can use bluetooth.drawerPin5();
  }
github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.