Showing
1 changed file
with
11 additions
and
6 deletions
| @@ -231,6 +231,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | @@ -231,6 +231,7 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | ||
| 231 | videoOutput.alwaysDiscardsLateVideoFrames = true | 231 | videoOutput.alwaysDiscardsLateVideoFrames = true |
| 232 | 232 | ||
| 233 | videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue.main) | 233 | videoOutput.setSampleBufferDelegate(self, queue: DispatchQueue.main) |
| 234 | + | ||
| 234 | captureSession.addOutput(videoOutput) | 235 | captureSession.addOutput(videoOutput) |
| 235 | for connection in videoOutput.connections { | 236 | for connection in videoOutput.connections { |
| 236 | connection.videoOrientation = .portrait | 237 | connection.videoOrientation = .portrait |
| @@ -243,22 +244,22 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | @@ -243,22 +244,22 @@ public class SwiftMobileScannerPlugin: NSObject, FlutterPlugin, FlutterStreamHan | ||
| 243 | 244 | ||
| 244 | let demensions = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription) | 245 | let demensions = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription) |
| 245 | 246 | ||
| 246 | - | ||
| 247 | /// limit captureSession area of interest to the scanWindow if provided | 247 | /// limit captureSession area of interest to the scanWindow if provided |
| 248 | - let scanWindowData: Array? = argReader.intArray(key: "scanWindow") | 248 | + let scanWindowData: Array? = argReader.floatArray(key: "scanWindow") |
| 249 | if(scanWindowData != nil) { | 249 | if(scanWindowData != nil) { |
| 250 | 250 | ||
| 251 | let captureMetadataOutput = AVCaptureMetadataOutput() | 251 | let captureMetadataOutput = AVCaptureMetadataOutput() |
| 252 | 252 | ||
| 253 | - let x = CGFloat(scanWindowData![0] / Int(demensions.width)) | ||
| 254 | - let y = CGFloat(scanWindowData![1] / Int(demensions.height)) | ||
| 255 | - let w = CGFloat((scanWindowData![2] - scanWindowData![0]) / Int(demensions.width)) | ||
| 256 | - let h = CGFloat((scanWindowData![3] - scanWindowData![1]) / Int(demensions.height)) | 253 | + let x = scanWindowData![0] / CGFloat(demensions.width) |
| 254 | + let y = scanWindowData![1] / CGFloat(demensions.height) | ||
| 255 | + let w = scanWindowData![2] - scanWindowData![0] / CGFloat(demensions.width) | ||
| 256 | + let h = scanWindowData![3] - scanWindowData![1] / CGFloat(demensions.height) | ||
| 257 | 257 | ||
| 258 | captureMetadataOutput.rectOfInterest = CGRect(x: x, y: y, width: w, height: h) | 258 | captureMetadataOutput.rectOfInterest = CGRect(x: x, y: y, width: w, height: h) |
| 259 | captureSession.addOutput(captureMetadataOutput) | 259 | captureSession.addOutput(captureMetadataOutput) |
| 260 | } | 260 | } |
| 261 | 261 | ||
| 262 | + | ||
| 262 | let width = Double(demensions.height) | 263 | let width = Double(demensions.height) |
| 263 | let height = Double(demensions.width) | 264 | let height = Double(demensions.width) |
| 264 | let size = ["width": width, "height": height] | 265 | let size = ["width": width, "height": height] |
| @@ -392,4 +393,8 @@ class MapArgumentReader { | @@ -392,4 +393,8 @@ class MapArgumentReader { | ||
| 392 | return args?[key] as? [Int] | 393 | return args?[key] as? [Int] |
| 393 | } | 394 | } |
| 394 | 395 | ||
| 396 | + func floatArray(key: String) -> [CGFloat]? { | ||
| 397 | + return args?[key] as? [CGFloat] | ||
| 398 | + } | ||
| 399 | + | ||
| 395 | } | 400 | } |
-
Please register or login to post a comment