0

我正在尝试保存使用视觉套件扫描的多张图像,但似乎只有第一张图像使用共享表保存。我该如何纠正这个问题。

扫描后保存图像

for i in 0...scan.pageCount-1 {
      let originalImage = scan.imageOfPage(at: i)
      let fixedImage =  originalImage.jpegData(compressionQuality: 0.7)
      let reloadedImage = UIImage(data: fixedImage!)
      let imagetoshare = [reloadedImage!]
      
      let activityViewController = UIActivityViewController(activityItems: imagetoshare, applicationActivities: nil)
      if let popoverController = activityViewController.popoverPresentationController {
      popoverController.sourceView = self.view
      popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
      popoverController.permittedArrowDirections = []
      }
      // exclude some activity types from the list (optional)
      // present the view controller
      self.present(activityViewController, animated: true, completion: nil)
}

由于 iPad 在调出共享表时出现问题,因此添加了 popover 控制器代码...

尝试保存多个图像时出现错误代码 I

2020-10-03 16:17:21.300830+0530 Scan Box[1163:132306] [ShareSheet] connection invalidated

如果您想知道 reloadedImage 函数是什么:

func reloadedImage(_ originalImage: UIImage) -> UIImage {
      guard let imageData = originalImage.jpegData(compressionQuality: 1),
            let reloadedImage = UIImage(data: imageData) else {
                return originalImage
      }
      return reloadedImage
}

编辑:我已经从 pageCount 中删除了“-1”,我收到了这个错误:

-[VNDocumentCameraScan imageOfPageAtIndex:]: index (2) beyond bounds (2).'

编辑2:

       var imagetoShare = [UIImage]()
                for i in 0...scan.pageCount-1 {
                    let originalImage = scan.imageOfPage(at: i)
                    let fixedImage =  originalImage.jpegData(compressionQuality: 0.7)
                    
                    let reloadedImage = UIImage(data: fixedImage!)
                    imagetoShare.append(reloadedImage!)
                  
                        
                        let activityViewController = UIActivityViewController(activityItems: imagetoShare, applicationActivities: nil)
                        if let popoverController = activityViewController.popoverPresentationController {
                        popoverController.sourceView = self.view
                          popoverController.sourceRect = CGRect(x: self.view.bounds.midX, y: self.view.bounds.midY, width: 0, height: 0)
                          popoverController.permittedArrowDirections = []
                            
                      }
                              
                              // exclude some activity types from the list (optional)


                              // present the view controller
                              self.present(activityViewController, animated: true, completion: nil)
                    

我什至尝试过:

imagetoShare: [UIImage] = [UIImage]()

但仍然没有运气

在这些更改之后,我的调试器日志显示,

2020-10-06 16:02:03.813409+0530 Scan Box[1706:336940] [] [16:02:03.811] SurfacePool_DetachSurface signalled err=-16990 (kFigPhotoError_InvalidParameter) (Surface not found in pool) at /Library/Caches/com.apple.xbs/Sources/EmbeddedCoreMedia/EmbeddedCoreMedia-2755.18.2.1.1/Sources/Photo/FigPhotoSurfacePool.c:1118
2020-10-06 16:02:06.469717+0530 Scan Box[1706:336940] [] [16:02:06.470] SurfacePool_DetachSurface signalled err=-16990 (kFigPhotoError_InvalidParameter) (Surface not found in pool) at /Library/Caches/com.apple.xbs/Sources/EmbeddedCoreMedia/EmbeddedCoreMedia-2755.18.2.1.1/Sources/Photo/FigPhotoSurfacePool.c:1118
2020-10-06 16:02:09.287991+0530 Scan Box[1706:336940] [Presentation] Attempt to present <UIActivityViewController: 0x102055600> on <UINavigationController: 0x102018e00> (from <Scan_Box.ViewController: 0x102019400>) while a presentation is in progress.
2020-10-06 16:02:09.290234+0530 Scan Box[1706:336940] [Presentation] Attempt to present <UIActivityViewController: 0x101a0f200> on <UINavigationController: 0x102018e00> (from <Scan_Box.ViewController: 0x102019400>) while a presentation is in progress.
2020-10-06 16:02:09.292873+0530 Scan Box[1706:337619] [ShareSheet] connection invalidated
2020-10-06 16:02:09.294701+0530 Scan Box[1706:338340] [ShareSheet] connection invalidated
2020-10-06 16:02:15.780167+0530 Scan Box[1706:338348] [ShareSheet] connection invalidated

请帮我解决这个问题。提前致谢!

4

1 回答 1

0

您创建了一堆 UIActivityViewController 以从代码中显示在循环中,因此只会显示其中的第一个,因为跳过了下一个。您应该首先创建要共享的图像数组,然后使用该数组显示控制器。

// Prepare array of images to share
var images = [UIImage]()
for i in 0...scan.pageCount-1 {
    ...
    images.append(reloadedImage!)
}
// Create and present single activity controller
let activityViewController = UIActivityViewController(activityItems: images, applicationActivities: nil)
...
self.present(activityViewController, animated: true, completion: nil)
于 2020-10-05T10:34:12.387 回答