Replies: 2 comments
-
We don't have that feature as of now, Moreover since you want to load local file, you don't need to rely on the this package. You could simply add an option to pick file from local folder and then you can decode it. similar package here. |
Beta Was this translation helpful? Give feedback.
0 replies
-
Scanning Barcodes from ImagesIf you need to scan barcodes from images stored on the phone, you can use the google_mlkit_barcode_scanning library: dependencies:
google_mlkit_barcode_scanning: ^0.13.0 Example ImplementationHere’s an example of how to scan a barcode from an image stored on the phone: Future<String?> imageAnalysisScan(BuildContext context) async {
try {
final XFile? image = await _pickImage();
if (image == null) {
AppToast.showErrorToast('لم يتم اختيار الصورة');
return null;
}
final String? barcode = await _getBarcodeFromImage(image);
if (barcode == null) {
AppToast.showErrorToast('الصورة غير واضحة أو لا تحتوي على باركود ');
return null;
}
if (!isNumber(barcode)) {
AppToast.showErrorToast(
'الباركود :$barcode غير صالح، يجب أن يكون رقمًا فقط');
return null;
}
return barcode;
} catch (e) {
AppToast.showErrorToast('حدث خطأ أثناء تحليل الصورة: \${e.toString()}');
return null;
}
}
Future<XFile?> _pickImage() async {
try {
final ImagePicker imagePicker = ImagePicker();
final XFile? image = await imagePicker.pickImage(
source: ImageSource.gallery,
imageQuality: 45,
);
return image;
} catch (e) {
AppToast.showErrorToast('حدث خطأ أثناء اختيار الصورة: \${e.toString()}');
return null;
}
}
Future<String?> _getBarcodeFromImage(XFile image) async {
try {
final InputImage inputImage = InputImage.fromFilePath(image.path);
final BarcodeScanner barcodeScanner = BarcodeScanner();
final List<Barcode> barcodes =
await barcodeScanner.processImage(inputImage);
if (barcodes.isEmpty) {
return null;
}
return barcodes.first.rawValue;
} catch (e) {
AppToast.showErrorToast('حدث خطأ أثناء معالجة الصورة: \${e.toString()}');
return null;
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi everyone, thanks for the great work. I was wondering if this library can let users scan barcodes from images that are stored in the phone.
Beta Was this translation helpful? Give feedback.
All reactions