PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, September 18, 2022

[FIXED] How to print images using Flutter and a Thermal Bluetooth Printer

 September 18, 2022     bluetooth, dart, flutter, printing, thermal-printer     No comments   

Issue

I have a "sales receipt" screen, so I need to print this using a bluetooth thermal printer, but when I try to print an image, I just receive a "black" square printed.

Print result (the image is just a logo with no background, so I tried with different pictures too, but no success)

Printed image as a black square

Code using blue_thermal_printer package (I tried with other packages but I had the same result)

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;
}

Please, can someone tell me what I'm doing wrong?


Solution

My mistake was use a png "without background" to print using a thermal printer. When I used an image with a white background it worked.



Answered By - Thierry P. Oliveira
Answer Checked By - Senaida (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing