【问题标题】:How to print images using Flutter and a Thermal Bluetooth Printer如何使用 Flutter 和热敏蓝牙打印机打印图像
【发布时间】:2022-02-02 12:16:26
【问题描述】:

我有一个“销售收据”屏幕,所以我需要使用蓝牙热敏打印机打印,但是当我尝试打印图像时,我只收到一个打印的“黑色”方块。

打印结果(图片只是一个没有背景的logo,所以我也尝试了不同的图片,但没有成功)

使用 blue_thermal_printer 包的代码(我尝试使用其他包,但结果相同)

printContent(BluetoothDevice device) async {
  await connectToPrinter(device);

  final imageBytes = await imagePathToUint8List('assets/images/logo_ps.png');
  await bluetooth.printImageBytes(imageBytes);
  await bluetooth.paperCut();

  await disconnectToPrinter();
}

Future<Uint8List> imagePathToUint8List(String path) async {
//converting to Uint8List to pass to printer

  ByteData data = await rootBundle.load(path);
  Uint8List imageBytes =
    data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
  return imageBytes;
}

拜托,谁能告诉我我做错了什么?

【问题讨论】:

    标签: flutter dart printing bluetooth thermal-printer


    【解决方案1】:

    我的错误是使用“无背景”的 png 来使用热敏打印机进行打印。当我使用具有白色背景的图像时,它起作用了。

    【讨论】:

      猜你喜欢
      • 2019-11-23
      • 2022-12-25
      • 1970-01-01
      • 2019-08-27
      • 2018-04-28
      • 2013-06-03
      • 2019-01-27
      • 1970-01-01
      • 2015-07-29
      相关资源
      最近更新 更多