【问题标题】:Get all Images from Live Photo从 Live Photo 中获取所有图像
【发布时间】:2016-10-13 20:45:51
【问题描述】:

我想从 Live Photo 中获取带有所有 UIImageNSArray 来创建它的 GIF。我尝试在为实时照片制作动画时制作屏幕截图,但它不起作用。 谁能帮我? 谢谢!

【问题讨论】:

  • 您可能必须通过 MOV,请参阅 here

标签: objective-c xcode phlivephoto apple-live-photos


【解决方案1】:

第一步,您需要将实时照片转换为视频,使用以下方法:

PHAssetResourceManager.defaultManager().writeDataForAssetResource(assetRes, 
    toFile: fileURL, options: nil, completionHandler: 
  {
     // Video file has been written to path specified via fileURL
  }

最后,使用这个库把它转成GIF,或者你可以在google中搜索另一种方式:https://github.com/NSRare/NSGIF

希望这会对你有所帮助。

【讨论】:

    【解决方案2】:

    这就是我为实现您所要求的相同目标所做的。

        PHFetchOptions *options = [[PHFetchOptions alloc] init];
        options.sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"creationDate" ascending:NO]];
        options.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d", PHAssetMediaTypeImage];
        options.predicate = [NSPredicate predicateWithFormat:@"mediaSubtype == %d", PHAssetMediaSubtypePhotoLive];
        options.includeAllBurstAssets = NO;
        PHFetchResult *allLivePhotos = [PHAsset fetchAssetsWithOptions:options];
        NSLog(@"Get total live count : %ld",(unsigned long)allLivePhotos.count);
        NSMutableArray *arrAllLiveImagesGroups = [NSMutableArray array];
    
        for (PHAsset *asset in allLivePhotos) {
            [asset requestContentEditingInputWithOptions:nil
                                       completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
                                           NSURL *urlMov = [contentEditingInput.livePhoto valueForKey:@"videoURL"];
    
                                           NSMutableArray *arrLive = [NSMutableArray array];
                                           NSMutableArray *arrSingleLiveImagesGroup = [NSMutableArray array];
                                           AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:urlMov options:nil];
                                           AVAssetImageGenerator *generator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
                                           generator.requestedTimeToleranceAfter =  kCMTimeZero;
                                           generator.requestedTimeToleranceBefore =  kCMTimeZero;
    
                                           for (Float64 i = 0; i < CMTimeGetSeconds(asset.duration) *  5 ; i++){
                                               @autoreleasepool {
                                                   CMTime time = CMTimeMake(i, 5);
                                                   NSError *err;
                                                   CMTime actualTime;
                                                   CGImageRef image = [generator copyCGImageAtTime:time actualTime:&actualTime error:&err];
                                                   UIImage *generatedImage = [[UIImage alloc] initWithCGImage:image scale:1.0 orientation:UIImageOrientationDown];
                                                   [arrLive addObject:generatedImage];
                                                   CGImageRelease(image);
                                               }
                                           }
                                           [arrSingleLiveImagesGroup addObject:arrLive];
                                           [arrAllLiveImagesGroups addObject:arrSingleLiveImagesGroup];
                                       }];
        }
    

    【讨论】:

      猜你喜欢
      • 2016-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-10
      • 2021-04-05
      • 1970-01-01
      • 1970-01-01
      • 2020-06-26
      相关资源
      最近更新 更多