【问题标题】:Incorrect image written to iOS photo album写入 iOS 相册的图像不正确
【发布时间】:2018-01-09 16:09:21
【问题描述】:

我正在使用UIImageWriteToSavedPhotosAlbum() 将图像保存到设备的相册中。

我将图像放在一个数组中,它们显示在 PageControl 上。

navigationBar 上的下载图标将图像保存到Photos

我可以将图像保存到Photos,但保存的图像不正确,即未保存特定索引处的图像。这就是我将所有图像添加到页面控件的方式......

func scrollImagesWhileViewChange() {

    for i in arrayOfURLImages {

    self.pageControl.size(forNumberOfPages: arrayOfURLImages.count)
        let scrollViewWidth:CGFloat = self.scrollView.frame.width
        let scrollViewHeight:CGFloat = self.scrollView.frame.height
        let index = arrayOfURLImages.index(of: i)
        let imageA = UIImageView(frame: CGRect(x: CGFloat(index!) * scrollViewWidth, y:0,width:scrollViewWidth, height:scrollViewHeight))
        imageA.image = i
        self.scrollView.addSubview(imageA)
        self.imageToDownload = imageA
        self.scrollView.contentSize = CGSize(width:self.scrollView.frame.width * CGFloat(arrayOfURLImages.count), height:self.scrollView.frame.height)
        self.scrollView.delegate = self
        self.pageControl.numberOfPages = arrayOfURLImages.count
        self.pageControl.currentPage = 0

}
}

self.imageToDownload = imageA 部分中,我将图像分配给 UIImageView 变量。这就是我保存到“照片”的方式..

UIImageWriteToSavedPhotosAlbum(self.imageToDownload.image!, self, #selector(MyViewController.image(_:didFinishSavingWithError:contextInfo:)), nil)

这里第一个参数应该得到正确的索引。但我无法弄清楚如何......

【问题讨论】:

    标签: ios swift uiscrollview uiimageview uipagecontrol


    【解决方案1】:

    当您点击下载按钮时,您需要找出页面控件的当前索引,然后根据当前索引从arrayOfURLImages获取正确的图像,然后保存到相册。

    试试这个-

    UIImageWriteToSavedPhotosAlbum(arrayOfURLImages[self.pageControl.currentPage], self, #selector(MyViewController.image(_:didFinishSavingWithError:contextInfo:)), nil)
    

    【讨论】:

    • 是的..这就是我所困惑的......如何在这部分 UIImageWriteToSavedPhotosAlbum(self.imageToDownload.image!....跨度>
    猜你喜欢
    • 2016-08-22
    • 2012-02-16
    • 2017-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-28
    相关资源
    最近更新 更多