'Flutter can I print images on a USB printer with the quick_usb package?

I am making an app that prints PDFs or images using a USB printer.
If you load an image of an asset and print it with a USB printer, text is printed, not the image.

Asset image loading method

Uint8List? imageData;

void loadAsset() async {
    Uint8List data = (await rootBundle.load('assets/images/1-1.JPG'))
        .buffer
        .asUint8List();
    setState(() => this.imageData = data);
  }

Initialize with the init button

 Widget _init_exit() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        RaisedButton(
          child: Text('init'),
          onPressed: () async {
            var init = await QuickUsb.init();
            loadAsset();
            log('init $init');
          },
        ),
        RaisedButton(
          child: Text('exit'),
          onPressed: () async {
            await QuickUsb.exit();
            log('exit');
          },
        ),
      ],
    );
  }

Grant the permission of the connected device.

    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        RaisedButton(
          child: Text('hasPermission'),
          onPressed: () async {
            var hasPermission = await QuickUsb.hasPermission(_deviceList!.first);
            log('hasPermission $hasPermission');
          },
        ),
        RaisedButton(
          child: Text('requestPermission'),
          onPressed: () async {
            await QuickUsb.requestPermission(_deviceList!.first);
            log('requestPermission');
          },
        ),
      ],
    );
  }

Now we do input/output. Output the imageData from which the image of the asset was loaded.

 Widget _bulk_transfer(){

    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceEvenly,
      children: [
        RaisedButton(
          child: Text('bulkTransferIn'),
          onPressed: () async {
            var endpoint = _configuration!.interfaces[0].endpoints
                .firstWhere((e) => e.direction == UsbEndpoint.DIRECTION_IN);
            var bulkTransferIn = await QuickUsb.bulkTransferIn(endpoint, 2048);
            log('bulkTransferIn ${hex.encode(bulkTransferIn)}');
          },
        ),
        RaisedButton(
          child: Text('bulkTransferOut'),
          onPressed: () async {

            var data = Uint8List.fromList(imageData!);
            var endpoint = _configuration!.interfaces[0].endpoints
                .firstWhere((e) => e.direction == UsbEndpoint.DIRECTION_OUT);
            var bulkTransferOut =
            await QuickUsb.bulkTransferOut(endpoint, data);
            log('bulkTransferOut $bulkTransferOut');
          },
        ),
      ],
    );
  }

However, it is output as text, not as an image. I want to output an image, not text.

If you know of any trivial advice or hints, please let me know.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source