我已经尝试了很多解决方案,但它们根本不起作用
extension ViewController: VNDocumentCameraViewControllerDelegate, UIImagePickerControllerDelegate {
func documentCameraViewController(_ controller: VNDocumentCameraViewController, didFinish scan: VNDocumentCameraScan) {
for pageNumber in 0..<scan.pageCount {
let image = scan.imageOfPage(at: pageNumber)
print(image)
//save
hasPhoto = true
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
//UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}
controller.dismiss(animated: true, completion: nil)
}
}发布于 2020-11-22 07:14:24
步骤1:向.plist添加权限
<key>NSPhotoLibraryAddUsageDescription</key>
<string>DummyProject wants to access your photo library to save photo</string>根据您的需要更改消息。
步骤2:确保您的图像不是0.
func saveImage(image: UIImage) {
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(_:didFinishSavingWithError:contextInfo:)), nil)
}步骤3:方法中的,检查错误:
@objc func image(_ image: UIImage, didFinishSavingWithError error: Error?, contextInfo: UnsafeRawPointer) {
guard error == nil else {
print(error ?? "Error in Image saving")
return
}
}如果您有任何问题,请评论。很乐意帮忙!
发布于 2020-11-22 07:46:31
对于pageNumber in 0..
UIImage* im = [UIImage imageWithCGImage: image.CGImage]; // make image from CGRef
NSData* imdata = UIImagePNGRepresentation ( im ); // get PNG representation
UIImage* im2 = [UIImage imageWithData:imdata]; // wrap UIImage around PNG representation
UIImageWriteToSavedPhotosAlbum(im2, nil, nil, nil); // save to photo album
}https://stackoverflow.com/questions/64951473
复制相似问题