简体   繁体   English

通过 POS 系统在收据上打印我们的图像时出错

[英]Error on printing our Images on Receipt via POS system

Here is my code below.下面是我的代码。

 Future<List<int>> getImage() async {
    List<int> bytes = [];
    CapabilityProfile profile = await CapabilityProfile.load();
    final generator = Generator(PaperSize.mm80, profile);

    final ByteData data = await rootBundle.load('assets/logo.png');
    final buffer = data.buffer;
    final image = base64.encode(Uint8List.view(buffer));
    bytes += generator.image(image);

    return bytes;
  }

At

bytes += generator.image(image); 

the error said that错误说

Error: The argument type 'String' can't be assigned to the parameter type 'Image'.错误:无法将参数类型“String”分配给参数类型“Image”。

from The docs来自文档

you need to pass the bytes not the base64你需要传递字节而不是 base64

it looks like you miss decodeImage()看起来你错过了decodeImage()

Future<List<int>> getImage() async {
    List<int> bytes = [];
    CapabilityProfile profile = await CapabilityProfile.load();
    final generator = Generator(PaperSize.mm80, profile);

    final ByteData data = await rootBundle.load('assets/logo.png');
    final Uint8List buffer = data.buffer.asUint8List();
    final Image image = decodeImage(buffer);

    bytes += generator.image(image);

    return bytes;
  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 有没有办法解决flutter在pos系统打印图片的问题? - Is there anyway can I solve the images issues printing out on pos system via flutter? 使用 Flutter 打印到 ESC/POS 时如何防止套接字超时错误 - How to prevent socket timeout error when printing to ESC/POS with Flutter 如何在 Flutter 中使用带有打印机名称的以太网 POS 打印机打印收据? - How to print receipt with ethernet POS printer with printer name in Flutter? 从 dart/flutter 在 POS USB 打印机上打印 - Printing on POS USB printer from dart/flutter 便携式POS系统POS Model:TC-TOUCH-T2 Flutter - Portable POS System POS Model: TC-TOUCH-T2 Flutter flutter中适合POS系统的本地数据库是什么? - what are the local database in flutter suitable for POS system? 是否可以在颤振中使用我们的自定义键盘而不是系统键盘? - is it possible to use our custom keyboard instead of system keyboard in flutter? 使用 flutter 中的 esc_pos_printer wifi 热敏打印机插件打印“£”符号 - printing a '£' symbol using esc_pos_printer wifi thermal printer plugin in flutter 颤振错误:断言失败:第 1785 行 pos 12:&#39;hasSize&#39; - Flutter error:Failed assertion: line 1785 pos 12: 'hasSize' 通过 usb - Flutter 使用热敏打印机打印 - Printing with thermal printers via usb - Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM