【问题标题】:Uploading duplicate images from camera roll in swift 3,4快速上传相机胶卷中的重复图像 3,4
【发布时间】:2018-03-31 02:05:56
【问题描述】:

我已经使用这个 DKImagePickerController 一年了,直到最近,我尝试从相机胶卷上传到我的应用程序的多张图片显示在其中一张图片的副本中. IE。我从相册中选择了三张图片,第三张图片上传了三次。我已经进行了广泛的调试并使用了不同的方法来访问图像的数据。我在 swift 3.2 和 4 以及您最新的 beta 版本上都使用了 3.8.1 版本。 我将尽可能详细地介绍我在单独的测试会话中使用的内容 swift 3.2 和 4,DK 版本 4.0.0 beta2

let documentDirectory = try! FileManager().url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)

for (i, asset) in assets.enumerated {
    let imageName = "tapan\(i).png"
    self.imgPathUrl = documentDirectory.appendingPathComponent(imageName)
   //loop header is the same for the rest
   asset.fetchOriginalImage(completeBlock: { (image, info) in
      let newImg = self.resizeImage(image!, newWidth: self.view.frame.width) //changes size
      let jpegData = UIImageJPEGRepresentation(newImg, 1)

      do{
        try jpegData?.write(to: self.imgPathUrl, options: .atomic)
      }catch{
         print("Write image to url failed ")
      }

      self.arrSelectedGalleryMedia.add(self.imgPathUrl)
      if self.arrSelectedGalleryMedia.count >= assets.count{
          SharedClass.sharedInstance.hideLoader()
           self.addMedia() //add images
          }
    })
 }

///在单独的循环中

asset.fetchImageData(completeBlock: {(data,info) in
     do{
         try data?.write(to: self.imgPathUrl, options: .atomic)
        }catch{
          print("Error\(error)")
        }

       self.arrSelectedGalleryMedia.add(self.imgPathUrl)
       if self.arrSelectedGalleryMedia.count >= assets.count{
            SharedClass.sharedInstance.hideLoader()
            self.addMedia() //add images
       }
 })

Swift 3.2 和 4,DK 版本 3.8.1

`

asset.fetchOriginalImageWithCompleteBlock({ (image, info) in
  let newImg = self.resizeImage(image!, newWidth: self.view.frame.width)
  let jpegData = UIImageJPEGRepresentation(newImg, 1)

  do{
      try jpegData?.write(to: self.imgPathUrl, options: .atomic)
    }catch{
       print("Write image to url failed ")
    }
   self.arrSelectedGalleryMedia.add(self.imgPathUrl)
   if self.arrSelectedGalleryMedia.count >= assets.count{
        SharedClass.sharedInstance.hideLoader()
        self.addMedia() //add images
    }
})

` 我在 3.8.1 中使用了另一个函数,它直接将数据写入临时 URL,并将链接存储在数组中。

问题似乎来自 getImageDataManager().fetchImageData。 就像我提到的示例中一样,我可以看到资产已被收集,但当我遍历每个资产时,它会跳过前两个并在第三个图像上循环 3 次。 任何帮助将不胜感激...

【问题讨论】:

  • imgPathUrl 的值是多少?
  • 一个临时 URL,我将使用它来写入图像。我用我使用的行更新了问题

标签: ios swift


【解决方案1】:

我使用了不同的库。 TLPhotoPicker。 DKImagePicker 可能需要先解决此问题。我早些时候在github 上开了一张票。希望他们能为他们的图书馆找到解决方案

extension addMediaViewController: TLPhotosPickerViewControllerDelegate{
    func dismissPhotoPicker(withTLPHAssets: [TLPHAsset]) {
    }
}

【讨论】:

    猜你喜欢
    • 2016-11-08
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 2019-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多