Showing
2 changed files
with
9 additions
and
3 deletions
| @@ -432,13 +432,16 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -432,13 +432,16 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 432 | } | 432 | } |
| 433 | 433 | ||
| 434 | /// Analyze a single image | 434 | /// Analyze a single image |
| 435 | - func analyzeImage(image: UIImage, position: AVCaptureDevice.Position, callback: @escaping BarcodeScanningCallback) { | 435 | + func analyzeImage(image: UIImage, position: AVCaptureDevice.Position, |
| 436 | + barcodeScannerOptions: BarcodeScannerOptions?, callback: @escaping BarcodeScanningCallback) { | ||
| 436 | let image = VisionImage(image: image) | 437 | let image = VisionImage(image: image) |
| 437 | image.orientation = imageOrientation( | 438 | image.orientation = imageOrientation( |
| 438 | deviceOrientation: UIDevice.current.orientation, | 439 | deviceOrientation: UIDevice.current.orientation, |
| 439 | defaultOrientation: .portrait, | 440 | defaultOrientation: .portrait, |
| 440 | position: position | 441 | position: position |
| 441 | ) | 442 | ) |
| 443 | + | ||
| 444 | + let scanner: BarcodeScanner = barcodeScannerOptions != nil ? BarcodeScanner.barcodeScanner(options: barcodeScannerOptions!) : BarcodeScanner.barcodeScanner() | ||
| 442 | 445 | ||
| 443 | scanner.process(image, completion: callback) | 446 | scanner.process(image, completion: callback) |
| 444 | } | 447 | } |
| @@ -253,7 +253,9 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | @@ -253,7 +253,9 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | ||
| 253 | 253 | ||
| 254 | /// Analyzes a single image. | 254 | /// Analyzes a single image. |
| 255 | private func analyzeImage(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { | 255 | private func analyzeImage(_ call: FlutterMethodCall, _ result: @escaping FlutterResult) { |
| 256 | - let uiImage = UIImage(contentsOfFile: call.arguments as? String ?? "") | 256 | + let formats: Array<Int> = (call.arguments as! Dictionary<String, Any?>)["formats"] as? Array ?? [] |
| 257 | + let scannerOptions: BarcodeScannerOptions? = buildBarcodeScannerOptions(formats) | ||
| 258 | + let uiImage = UIImage(contentsOfFile: (call.arguments as! Dictionary<String, Any?>)["filePath"] as? String ?? "") | ||
| 257 | 259 | ||
| 258 | if (uiImage == nil) { | 260 | if (uiImage == nil) { |
| 259 | result(FlutterError(code: "MobileScanner", | 261 | result(FlutterError(code: "MobileScanner", |
| @@ -262,7 +264,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | @@ -262,7 +264,8 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | ||
| 262 | return | 264 | return |
| 263 | } | 265 | } |
| 264 | 266 | ||
| 265 | - mobileScanner.analyzeImage(image: uiImage!, position: AVCaptureDevice.Position.back, callback: { barcodes, error in | 267 | + mobileScanner.analyzeImage(image: uiImage!, position: AVCaptureDevice.Position.back, |
| 268 | + barcodeScannerOptions: scannerOptions, callback: { barcodes, error in | ||
| 266 | if error != nil { | 269 | if error != nil { |
| 267 | DispatchQueue.main.async { | 270 | DispatchQueue.main.async { |
| 268 | result(FlutterError(code: "MobileScanner", | 271 | result(FlutterError(code: "MobileScanner", |
-
Please register or login to post a comment