Showing
2 changed files
with
27 additions
and
7 deletions
| @@ -25,9 +25,6 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -25,9 +25,6 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 25 | /// Barcode scanner for results | 25 | /// Barcode scanner for results |
| 26 | var scanner = BarcodeScanner.barcodeScanner() | 26 | var scanner = BarcodeScanner.barcodeScanner() |
| 27 | 27 | ||
| 28 | - /// Return image buffer with the Barcode event | ||
| 29 | - var returnImage: Bool = false | ||
| 30 | - | ||
| 31 | /// Default position of camera | 28 | /// Default position of camera |
| 32 | var videoPosition: AVCaptureDevice.Position = AVCaptureDevice.Position.back | 29 | var videoPosition: AVCaptureDevice.Position = AVCaptureDevice.Position.back |
| 33 | 30 | ||
| @@ -172,7 +169,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -172,7 +169,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 172 | } | 169 | } |
| 173 | 170 | ||
| 174 | /// Start scanning for barcodes | 171 | /// Start scanning for barcodes |
| 175 | - func start(barcodeScannerOptions: BarcodeScannerOptions?, returnImage: Bool, cameraPosition: AVCaptureDevice.Position, torch: Bool, detectionSpeed: DetectionSpeed, completion: @escaping (MobileScannerStartParameters) -> ()) throws { | 172 | + func start(barcodeScannerOptions: BarcodeScannerOptions?, cameraPosition: AVCaptureDevice.Position, torch: Bool, detectionSpeed: DetectionSpeed, completion: @escaping (MobileScannerStartParameters) -> ()) throws { |
| 176 | self.detectionSpeed = detectionSpeed | 173 | self.detectionSpeed = detectionSpeed |
| 177 | if (device != nil || captureSession != nil) { | 174 | if (device != nil || captureSession != nil) { |
| 178 | throw MobileScannerError.alreadyStarted | 175 | throw MobileScannerError.alreadyStarted |
| @@ -12,6 +12,10 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | @@ -12,6 +12,10 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | ||
| 12 | /// The handler sends all information via an event channel back to Flutter | 12 | /// The handler sends all information via an event channel back to Flutter |
| 13 | private let barcodeHandler: BarcodeHandler | 13 | private let barcodeHandler: BarcodeHandler |
| 14 | 14 | ||
| 15 | + /// Whether to return the input image with the barcode event. | ||
| 16 | + /// This is static to avoid accessing `self` in the callback in the constructor. | ||
| 17 | + private static var returnImage: Bool = false | ||
| 18 | + | ||
| 15 | /// The points for the scan window. | 19 | /// The points for the scan window. |
| 16 | static var scanWindow: [CGFloat]? | 20 | static var scanWindow: [CGFloat]? |
| 17 | 21 | ||
| @@ -58,9 +62,27 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | @@ -58,9 +62,27 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | ||
| 58 | return nil | 62 | return nil |
| 59 | } | 63 | } |
| 60 | 64 | ||
| 61 | - if (!barcodesMap.isEmpty) { | ||
| 62 | - barcodeHandler.publishEvent(["name": "barcode", "data": barcodesMap, "image": FlutterStandardTypedData(bytes: image.jpegData(compressionQuality: 0.8)!), "width": image.size.width, "height": image.size.height]) | 65 | + if (barcodesMap.isEmpty) { |
| 66 | + return | ||
| 67 | + } | ||
| 68 | + | ||
| 69 | + if (!MobileScannerPlugin.returnImage) { | ||
| 70 | + barcodeHandler.publishEvent([ | ||
| 71 | + "name": "barcode", | ||
| 72 | + "data": barcodesMap, | ||
| 73 | + ]) | ||
| 74 | + return | ||
| 63 | } | 75 | } |
| 76 | + | ||
| 77 | + barcodeHandler.publishEvent([ | ||
| 78 | + "name": "barcode", | ||
| 79 | + "data": barcodesMap, | ||
| 80 | + "image": [ | ||
| 81 | + "bytes": FlutterStandardTypedData(bytes: image.jpegData(compressionQuality: 0.8)!), | ||
| 82 | + "width": image.size.width, | ||
| 83 | + "height": image.size.height, | ||
| 84 | + ], | ||
| 85 | + ]) | ||
| 64 | }, torchModeChangeCallback: { torchState in | 86 | }, torchModeChangeCallback: { torchState in |
| 65 | barcodeHandler.publishEvent(["name": "torchState", "data": torchState]) | 87 | barcodeHandler.publishEvent(["name": "torchState", "data": torchState]) |
| 66 | }, zoomScaleChangeCallback: { zoomScale in | 88 | }, zoomScaleChangeCallback: { zoomScale in |
| @@ -110,6 +132,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | @@ -110,6 +132,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | ||
| 110 | let speed: Int = (call.arguments as! Dictionary<String, Any?>)["speed"] as? Int ?? 0 | 132 | let speed: Int = (call.arguments as! Dictionary<String, Any?>)["speed"] as? Int ?? 0 |
| 111 | let timeoutMs: Int = (call.arguments as! Dictionary<String, Any?>)["timeout"] as? Int ?? 0 | 133 | let timeoutMs: Int = (call.arguments as! Dictionary<String, Any?>)["timeout"] as? Int ?? 0 |
| 112 | self.mobileScanner.timeoutSeconds = Double(timeoutMs) / Double(1000) | 134 | self.mobileScanner.timeoutSeconds = Double(timeoutMs) / Double(1000) |
| 135 | + MobileScannerPlugin.returnImage = returnImage | ||
| 113 | 136 | ||
| 114 | let formatList = formats.map { format in return BarcodeFormat(rawValue: format)} | 137 | let formatList = formats.map { format in return BarcodeFormat(rawValue: format)} |
| 115 | var barcodeOptions: BarcodeScannerOptions? = nil | 138 | var barcodeOptions: BarcodeScannerOptions? = nil |
| @@ -126,7 +149,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | @@ -126,7 +149,7 @@ public class MobileScannerPlugin: NSObject, FlutterPlugin { | ||
| 126 | let detectionSpeed: DetectionSpeed = DetectionSpeed(rawValue: speed)! | 149 | let detectionSpeed: DetectionSpeed = DetectionSpeed(rawValue: speed)! |
| 127 | 150 | ||
| 128 | do { | 151 | do { |
| 129 | - try mobileScanner.start(barcodeScannerOptions: barcodeOptions, returnImage: returnImage, cameraPosition: position, torch: torch, detectionSpeed: detectionSpeed) { parameters in | 152 | + try mobileScanner.start(barcodeScannerOptions: barcodeOptions, cameraPosition: position, torch: torch, detectionSpeed: detectionSpeed) { parameters in |
| 130 | DispatchQueue.main.async { | 153 | DispatchQueue.main.async { |
| 131 | result([ | 154 | result([ |
| 132 | "textureId": parameters.textureId, | 155 | "textureId": parameters.textureId, |
-
Please register or login to post a comment