Save GIF image from URL to Camera Roll

耗尽温柔 提交于 2019-12-23 03:04:13

问题


I'm trying to save a GIF from URL to Camera Roll with the following code:

var image = UIImage(data: NSData(contentsOfURL: self.imageView.sd_imageURL())!)
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)

but after saving, the GIF become a still image, anyone can help me? Thanks!


回答1:


Try this:

import AssetsLibrary


let image = NSData(contentsOfURL: url)

ALAssetsLibrary().writeImageDataToSavedPhotosAlbum(image, metadata: nil, completionBlock: { (assetURL: NSURL!, error: NSError!) -> Void in
        print(assetURL)
})



回答2:


You can save GIF via PHPhotoLibrary

    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))
        }
    }


来源:https://stackoverflow.com/questions/32186219/save-gif-image-from-url-to-camera-roll

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!