ekasetiawans / flutter_bluetooth_printer_plugin

MIT License
21 stars 36 forks source link

How to print Image without using Receipt widget? #17

Open cheasoksereyoudom opened 1 year ago

cheasoksereyoudom commented 1 year ago

How to print Image without using Receipt widget? How to use only FlutterBluetoothPrinter.printImage() ?

final byteData = capturedImage.buffer.asByteData();
    final List<int> bytes = byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes,);

    final buffer = await ui.ImmutableBuffer.fromUint8List(capturedImage);
    final image = await ui.ImageDescriptor.encoded(buffer);

    final imageWidth = image.width;
    final imageHeight = image.height;

    print("imageWidth: ${imageWidth}, imageHeight: ${imageHeight}");

    FlutterBluetoothPrinter.printImage(
        address: bluetoothDevice!.value.address,
        imageBytes: bytes,
        imageWidth: imageWidth,
        imageHeight: imageHeight,
        addFeeds: 1,
        keepConnected: true,
        useImageRaster: true,
        paperSize: PaperSize.mm58);
    }

this my code and this is error

E/flutter ( 4048): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (index): Index out of range: index should be less than 13186: 13186
E/flutter ( 4048): #0      Uint32List.[] (dart:typed_data-patch/typed_data_patch.dart:2560:7)
E/flutter ( 4048): #1      Image.getPixel (package:image/src/image.dart:422:37)
E/flutter ( 4048): #2      convolution (package:image/src/filter/convolution.dart:26:26)
E/flutter ( 4048): #3      smooth (package:image/src/filter/smooth.dart:10:10)
E/flutter ( 4048): #4      FlutterBluetoothPrinter._blackwhiteInternal (package:flutter_bluetooth_printer/src/flutter_bluetooth_printer_impl.dart:134:15)
E/flutter ( 4048): #5      _IsolateConfiguration.applyAndTime.<anonymous closure> (package:flutter/src/foundation/_isolates_io.dart:108:21)
E/flutter ( 4048): #6      Timeline.timeSync (dart:developer/timeline.dart:160:22)
E/flutter ( 4048): #7      _IsolateConfiguration.applyAndTime (package:flutter/src/foundation/_isolates_io.dart:106:21)
E/flutter ( 4048): #8      _spawn (package:flutter/src/foundation/_isolates_io.dart:127:67)
E/flutter ( 4048): #9      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:300:17)
E/flutter ( 4048): #10     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
Denis3107 commented 1 year ago

I faced the same problem, did you find a solution to this problem ?

mahmoud-haj-ali commented 9 months ago

@cheasoksereyoudom did you find a solution?