andresperezmelo / print_bluetooth_thermal

Plugin para enviar bytes sin procesar a la impresora solo por ahora para Android
Other
27 stars 35 forks source link

Prints image only a part of it and then stop printing #28

Open vietdhfpt opened 1 year ago

vietdhfpt commented 1 year ago

I am using the image printing feature. However, while printing the image of the receipt works, it prints only a part of it and then stops printing. Thank you

Flutter code print

Future<List<int>> testTicket() async {
    List<int> bytes = [];
    // Using default profile
    final profile = await CapabilityProfile.load();
    final generator = Generator(
        optionprinttype == "58 mm" ? PaperSize.mm58 : PaperSize.mm80, profile);
    //bytes += generator.setGlobalFont(PosFontType.fontA);
    bytes += generator.reset();

    final ByteData data = await rootBundle.load('assets/test.jpg');
    final Uint8List bytesImg = data.buffer.asUint8List();
    img.Image? image = img.decodeImage(bytesImg);

    if (Platform.isIOS) {
      // Resizes the image to half its original size and reduces the quality to 80%
      final resizedImage = img.copyResize(
        image!,
        // width: image.width ~/ 1.3,
        // height: image.height ~/ 1.3,
        width: image.width,
        height: image.height,
        interpolation: img.Interpolation.cubic,
      );
      final bytesimg = Uint8List.fromList(img.encodeJpg(resizedImage));
      image = img.decodeImage(bytesimg);
    }

    //Using `ESC *`
    bytes += generator.image(image!);

    .....

Image size: size_image

Result: result_print

vietdhfpt commented 1 year ago

File image print receipt_print

andresperezmelo commented 12 months ago

Seeing the error message, you are printing a very large image, ticket printers support small images like logos or something like that, in most of the tests the perfect size was 200 width x 100 height px, although they reach 290 width px by 200 height px.

Another thing is that this receipt, should not be printed as an image should create the ticket directly, the suggested package can create such tickets so you do not have to print the whole image

jefelon commented 4 months ago

How did you solve this error? I found in another thread that they divided the image into several parts and sent those segments to be printed, but now I can't find it