part of 'zxing.dart'; /// Reads barcodes from String image path Future> readBarcodesImagePathString( String path, { int format = Format.Any, int cropWidth = 0, int cropHeight = 0, bool tryHarder = false, bool tryRotate = true, }) => readBarcodesImagePath( XFile(path), format: format, cropWidth: cropWidth, cropHeight: cropHeight, tryHarder: tryHarder, tryRotate: tryRotate, ); /// Reads barcodes from XFile image path Future> readBarcodesImagePath( XFile path, { int format = Format.Any, int cropWidth = 0, int cropHeight = 0, bool tryHarder = false, bool tryRotate = true, }) async { final Uint8List imageBytes = await path.readAsBytes(); final imglib.Image? image = imglib.decodeImage(imageBytes); if (image == null) { return []; } return readBarcodes( image.getBytes(format: imglib.Format.luminance), width: image.width, height: image.height, format: format, cropWidth: cropWidth, cropHeight: cropHeight, tryHarder: tryHarder, tryRotate: tryRotate, ); } /// Reads barcodes from image url Future> readBarcodesImageUrl( String url, { int format = Format.Any, int cropWidth = 0, int cropHeight = 0, bool tryHarder = false, bool tryRotate = true, }) async { final Uint8List imageBytes = (await NetworkAssetBundle(Uri.parse(url)).load(url)).buffer.asUint8List(); final imglib.Image? image = imglib.decodeImage(imageBytes); if (image == null) { return []; } return readBarcodes( image.getBytes(format: imglib.Format.luminance), width: image.width, height: image.height, format: format, cropWidth: cropWidth, cropHeight: cropHeight, tryHarder: tryHarder, tryRotate: tryRotate, ); } /// Reads barcodes from Uint8List image bytes List readBarcodes( Uint8List bytes, { required int width, required int height, int format = Format.Any, int cropWidth = 0, int cropHeight = 0, bool tryHarder = false, bool tryRotate = true, }) { final CodeResults result = bindings.readBarcodes( bytes.allocatePointer(), format, width, height, cropWidth, cropHeight, tryHarder ? 1 : 0, tryRotate ? 1 : 0, ); final List results = []; for (int i = 0; i < result.count; i++) { results.add(result.results.elementAt(i).ref); } return results; }