首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHPhotoLibrary保存gif数据

PHPhotoLibrary保存gif数据
EN

Stack Overflow用户
提问于 2016-02-13 01:16:56
回答 3查看 3.6K关注 0票数 3

在新的ALAssetsLibrary->writeImageDataToSavedPhotosAlbum中找不到与PHPhotoLibrary类似的方法,因为ALAssetsLibrary在iOS 9中不推荐使用,所以我无法保存GIF,可能我正在使用以下代码

代码语言:javascript
复制
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
        PHAssetChangeRequest *assetRequest = [PHAssetChangeRequest creationRequestForAssetFromImage:[UIImage imageWithData:gifdata]];
        placeholder = [assetRequest placeholderForCreatedAsset];
        photosAsset = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
        PHAssetCollectionChangeRequest *albumChangeRequest = [PHAssetCollectionChangeRequest changeRequestForAssetCollection:collection
                                                                                                                      assets:photosAsset];
        [albumChangeRequest addAssets:@[placeholder]];
    } completionHandler:^(BOOL success, NSError *error) {
        if (success)
        {

        }
        else
        {

            NSLog(@"%@", error);
        }
    }];
EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2016-02-13 02:16:09

我通过创建临时文件并使用:

creationRequestForAssetFromImageAtFileURL

票数 1
EN

Stack Overflow用户

发布于 2016-11-02 06:31:31

我使用NSData保存gif映像,ALAssetsLibrary方法UIImageWriteToSavedPhotosAlbum在iOS8之后不再推荐,api说我们可以使用PHAssetCreationRequest方法[[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:options];保存这个gif映像数据,所以您也可以使用url请求来保存gifs。

守则如下:

代码语言:javascript
复制
NSString *path = [[NSBundle mainBundle] pathForResource:@"1" ofType:@"gif"];
NSData *data = [NSData dataWithContentsOfFile:path];
[[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
    PHAssetResourceCreationOptions *options = [[PHAssetResourceCreationOptions alloc] init];
    [[PHAssetCreationRequest creationRequestForAsset] addResourceWithType:PHAssetResourceTypePhoto data:data options:options];
} completionHandler:^(BOOL success, NSError * _Nullable error) {
    NSLog(@":%d",success);
}];
票数 8
EN

Stack Overflow用户

发布于 2018-08-09 08:42:52

我已经通过使用Photos框架成功地将gif文件保存到Photos图片库

代码语言:javascript
复制
PHPhotoLibrary.shared().performChanges ({
    let url = URL(fileURLWithPath: "your file path")
    PHAssetChangeRequest.creationRequestForAssetFromImage(atFileURL: url)
  }) { saved, error in
    if saved {
      print("Your image was successfully saved")
    }
  }

希望能帮上忙!

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/35374919

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档