【发布时间】:2015-11-18 02:35:25
【问题描述】:
我正在尝试使用以下代码将 GIF 从 URL 保存到相机胶卷:
var image = UIImage(data: NSData(contentsOfURL: self.imageView.sd_imageURL())!)
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
但是保存后,GIF变成了静止图像,有人可以帮帮我吗? 谢谢!
【问题讨论】:
我正在尝试使用以下代码将 GIF 从 URL 保存到相机胶卷:
var image = UIImage(data: NSData(contentsOfURL: self.imageView.sd_imageURL())!)
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
但是保存后,GIF变成了静止图像,有人可以帮帮我吗? 谢谢!
【问题讨论】:
您可以通过 PHPhotoLibrary 保存 GIF
PHPhotoLibrary.shared().performChanges({
let request = PHAssetCreationRequest.forAsset()
request.addResource(with: .photo, fileURL: YOUR_GIF_URL, options: nil)
}) { (success, error) in
if let error = error {
completion(.failure(error))
} else {
completion(.success(true))
}
}
【讨论】:
试试这个:
import AssetsLibrary
let image = NSData(contentsOfURL: url)
ALAssetsLibrary().writeImageDataToSavedPhotosAlbum(image, metadata: nil, completionBlock: { (assetURL: NSURL!, error: NSError!) -> Void in
print(assetURL)
})
【讨论】: