我已经在框架内实现了视觉文档扫描仪。当调用相机视图控制器并捕获文档时。当点击保存按钮时,它应该关闭并返回到 viewController。
这是框架内的代码:
public func showScanner(){
self.createTaskController()
// let scannerViewController = VNDocumentCameraViewController()
// scannerViewController.delegate = self
// present(scannerViewController, animated: true)
print("Called Build")
}
private func createTaskController(){
let scannerViewController = VNDocumentCameraViewController()
scannerViewController.delegate = self
self.clientView?.addChild(scannerViewController)
self.clientView?.view.addSubview(scannerViewController.view)
scannerViewController.didMove(toParent: clientView)
scannerViewController.dismiss(animated: true)
}
public func imageFromFile(result: @escaping (_ image: UIImage?) -> Void){
//the image
if imageNew != nil {
result(imageNew)
}
else{
//callback nil so the app does not pause infinitely if
//the error != nil
result(nil)
}
}
public func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinishWith scan: VNDocumentCameraScan) {
guard scan.pageCount >= 1 else {
controller.dismiss(animated: true)
return
}
let originalImage = scan.imageOfPage(at: 0)
let newImage = compressedImage(originalImage)
imageNew = newImage
print("new image::\(newImage.size)")
print("new imagei::\(newImage)")
controller.dismiss(animated: true)
}
public func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFailWithError error: Error) {
print(error)
controller.dismiss(animated: true)
}
public func documentCameraViewControllerDidCancel(_ controller: VNDocumentCameraViewController) {
controller.dismiss(animated: true)
}
func compressedImage(_ originalImage: UIImage) -> UIImage {
guard let imageData = originalImage.jpegData(compressionQuality: 1),
let reloadedImage = UIImage(data: imageData) else {
return originalImage
}
return reloadedImage
}
这是我在示例项目中调用框架的代码:
@IBAction func btnAction(_ sender: Any) {
A8Scan(self).showScanner()
p()
}
我的问题是当点击保存按钮时,它应该关闭相机控制器(VNDocumentCameraViewController)并返回到示例应用程序。但是,就我而言,它没有返回。
任何帮助非常感谢请...