【问题标题】:How to convert PHAsset to PHLivePhoto如何将 PHAsset 转换为 PHLivePhoto
【发布时间】:2016-01-12 08:13:29
【问题描述】:

我有PHAsset,我想获得PHLivePhoto

PHAssetPHLivePhoto 的资产。

我知道这个函数。

/// Requests a Live Photo from the given resource URLs. The result handler will be called multiple times to deliver new PHLivePhoto instances with increasingly more content. If a placeholder image is provided, the result handler will first be invoked synchronously to deliver a live photo containing only the placeholder image. Subsequent invocations of the result handler will occur on the main queue.
//  The targetSize and contentMode parameters are used to resize the live photo content if needed. If targetSize is equal to CGRectZero, content will not be resized.
//  When using this method to provide content for a PHLivePhotoView, each live photo instance delivered via the result handler should be passed to -     [PHLivePhotoView setLivePhoto:].
+ (PHLivePhotoRequestID)requestLivePhotoWithResourceFileURLs:(NSArray<NSURL *> *)fileURLs placeholderImage:(UIImage *__nullable)image targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode resultHandler:(void(^)(PHLivePhoto *__nullable livePhoto, NSDictionary *info))resultHandler;

但我不知道怎么用。

如何转换?

【问题讨论】:

    标签: ios objective-c phlivephoto


    【解决方案1】:

    您可以在 PHImageManager 中使用此方法

    - (PHImageRequestID)requestLivePhotoForAsset:(PHAsset *)asset targetSize:(CGSize)targetSize contentMode:(PHImageContentMode)contentMode options:(PHLivePhotoRequestOptions *)options resultHandler:(void (^)(PHLivePhoto *livePhoto, NSDictionary *info))resultHandler
    

    在 resultHandler 中,您可以获得准备在 PHLivePhotoView 中显示的 PHLivePhoto。

    示例:

    [[PHImageManager defaultManager] requestLivePhotoForAsset:asset targetSize:self.contentView.frame.size contentMode:PHImageContentModeDefault options:nil resultHandler:^(PHLivePhoto * _Nullable livePhoto, NSDictionary * _Nullable info) { self.contentView.livePhoto = livePhoto  }];
    

    【讨论】:

      【解决方案2】:
      [asset requestContentEditingInputWithOptions:nil completionHandler:^(PHContentEditingInput *contentEditingInput, NSDictionary *info) {
      PHLivePhoto *livePhoto = [contentEditingInput.livePhoto];
      }];
      

      【讨论】:

        猜你喜欢
        • 2015-11-07
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-12-25
        • 1970-01-01
        • 1970-01-01
        • 2019-02-15
        • 2016-11-12
        相关资源
        最近更新 更多