@@ -34,6 +34,9 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate {
3434 /// If false then apply filters in post processing, otherwise instead of in camera preview
3535 @objc public var showPostProcessingFilters = true
3636
37+ //last parsed image
38+ @objc public var parsedImage : UIImage ?
39+
3740 // The parsing to be applied
3841 @objc public var mrzType : MRZType = MRZType . auto
3942
@@ -180,6 +183,11 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate {
180183 camera = try Camera ( sessionPreset: AVCaptureSession . Preset. hd1920x1080)
181184 camera. location = PhysicalCameraLocation . backFacing
182185
186+ if renderView== nil {
187+ renderView = RenderView . init ( frame: self . view. bounds)
188+ self . view. addSubview ( renderView)
189+ }
190+
183191 if !showPostProcessingFilters {
184192 // Apply only the cropping
185193 camera --> renderView
@@ -290,7 +298,14 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate {
290298 self . stopScan ( )
291299 }
292300
293-
301+ open func imageFromView( myView: UIView ) -> UIImage {
302+ UIGraphicsBeginImageContextWithOptions ( myView. bounds. size, myView. isOpaque, 0.0 )
303+ myView. drawHierarchy ( in: myView. bounds, afterScreenUpdates: true )
304+ let snapshotImageFromMyView = UIGraphicsGetImageFromCurrentImageContext ( )
305+ UIGraphicsEndImageContext ( )
306+ //print(snapshotImageFromMyView)
307+ return snapshotImageFromMyView!
308+ }
294309
295310 /**
296311 Processing the image
@@ -330,7 +345,15 @@ open class PassportScannerController: UIViewController, MGTesseractDelegate {
330345 if mrz. isValid ( ) < self . accuracy {
331346 print ( " Scan quality insufficient : \( mrz. isValid ( ) ) " )
332347 } else {
333- self . camera. stopCapture ( )
348+ DispatchQueue . main. async {
349+ let subviews = self . renderView. subviews
350+ for view in subviews {
351+ view. removeFromSuperview ( )
352+ }
353+ self . parsedImage = self . imageFromView ( myView: self . renderView)
354+ self . camera. stopCapture ( )
355+ }
356+
334357 DispatchQueue . main. async {
335358 self . successfulScan ( mrz: mrz)
336359 }
0 commit comments