Browse Source

correctly get bytes

pull/84/head
Khoren Markosyan 2 years ago
parent
commit
cb4f63f921
  1. 17
      lib/src/logic/barcode_reader.dart
  2. 4
      lib/src/logic/barcodes_reader.dart
  3. 1
      lib/src/ui/writer_widget.dart
  4. 10
      lib/src/utils/image_converter.dart

17
lib/src/logic/barcode_reader.dart

@ -16,23 +16,14 @@ Future<Code> zxingReadBarcodeImagePath(
DecodeParams? params,
}) async {
final Uint8List imageBytes = await path.readAsBytes();
final imglib.Image? image = imglib.decodeImage(imageBytes);
imglib.Image? image = imglib.decodeImage(imageBytes);
if (image == null) {
return Code();
}
// image = resizeToMaxSize(image, params?.maxSize);
// imglib.Image imgRgba8 = image.convert(
// format: imglib.Format.uint8,
// numChannels: 4,
// ); // Make sure it's an RGBA 32-bit image like v3
// imgRgba8 =
// imglib.grayscale(imgRgba8); // map the pixels to grayscale (luminance)
// final Uint8List bytes = imgRgba8.getBytes();
image = resizeToMaxSize(image, params?.maxSize);
return zxingReadBarcode(
image.toUint8List(), //.getBytes(format: imglib.Format.luminance),
grayscaleBytes(image),
width: image.width,
height: image.height,
params: params,
@ -52,7 +43,7 @@ Future<Code> zxingReadBarcodeImageUrl(
}
image = resizeToMaxSize(image, params?.maxSize);
return zxingReadBarcode(
image.toUint8List(), //.getBytes(format: imglib.Format.luminance),
grayscaleBytes(image),
width: image.width,
height: image.height,
params: params,

4
lib/src/logic/barcodes_reader.dart

@ -22,7 +22,7 @@ Future<Codes> zxingReadBarcodesImagePath(
}
image = resizeToMaxSize(image, params?.maxSize);
return zxingReadBarcodes(
image.toUint8List(), //.getBytes(format: imglib.Format.luminance),
grayscaleBytes(image),
width: image.width,
height: image.height,
params: params,
@ -42,7 +42,7 @@ Future<Codes> zxingReadBarcodesImageUrl(
}
image = resizeToMaxSize(image, params?.maxSize);
return zxingReadBarcodes(
image.toUint8List(), //.getBytes(format: imglib.Format.luminance),
grayscaleBytes(image),
width: image.width,
height: image.height,
params: params,

1
lib/src/ui/writer_widget.dart

@ -281,6 +281,7 @@ class _WriterWidgetState extends State<WriterWidget>
width: width,
height: height,
bytes: result.data!.buffer,
numChannels: 4,
);
final Uint8List encodedBytes = Uint8List.fromList(
imglib.encodeJpg(img),

10
lib/src/utils/image_converter.dart

@ -82,3 +82,13 @@ imglib.Image resizeToMaxSize(imglib.Image image, int? maxSize) {
}
return image;
}
// get the bytes of the image in grayscale format (luminance) like v3
Uint8List grayscaleBytes(imglib.Image image) {
final imglib.Image imgRgba8 = image.convert(
format: imglib.Format.uint8,
numChannels: 1,
); // Make sure it's an RGBA 32-bit image like v3
imglib.grayscale(imgRgba8); // map the pixels to grayscale (luminance)
return imgRgba8.getBytes();
}

Loading…
Cancel
Save