[英]Incorrect image written to iOS photo album
I am using UIImageWriteToSavedPhotosAlbum()
to save images to the photo album of the device. 我正在使用
UIImageWriteToSavedPhotosAlbum()
将图像保存到设备的相册中。
I have my images in an array and they are displayed on a PageControl
. 我将图像放在一个数组中,并将它们显示在
PageControl
。
A download icon on the navigationBar
saves the image to Photos
. navigationBar
上的下载图标将图像保存到Photos
。
I am able to save the image to Photos
but the image saved is incorrect ie the image at the particular index is not saved. 我可以将图像保存到
Photos
但是保存的图像不正确,即未保存特定索引处的图像。 This is how I am adding all images to the page-control.... 这就是我将所有图像添加到页面控件的方式。
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
}
}
In the section self.imageToDownload = imageA
, I am assigning the image to a UIImageView
variable. 在
self.imageToDownload = imageA
部分中,我将图像分配给UIImageView
变量。 And this is how I am saving to 'Photos'.. 这就是我保存到“照片”的方式。
UIImageWriteToSavedPhotosAlbum(self.imageToDownload.image!, self, #selector(MyViewController.image(_:didFinishSavingWithError:contextInfo:)), nil)
Here the first parameter should get the correct index. 在这里,第一个参数应该获得正确的索引。 But I am not able to figure out how...
但是我不知道怎么...
When you click download button you need to figure out the current index of page control and then on basis of current index fetch right image from arrayOfURLImages
and then save to photo album. 当您单击下载按钮时,您需要找出页面控件的当前索引,然后根据当前索引从
arrayOfURLImages
获取正确的图像,然后保存到相册。
Try this- 尝试这个-
UIImageWriteToSavedPhotosAlbum(arrayOfURLImages[self.pageControl.currentPage], self, #selector(MyViewController.image(_:didFinishSavingWithError:contextInfo:)), nil)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.