How to fetch squared thumbnails from PHImageManager?

后端 未结 5 832
日久生厌
日久生厌 2021-01-31 04:51

Has anybody idea how to fetch squared thumbs from PHImageManager? PHImageContentModeAspectFill option has no effect.

[[PHImageManager defaultManager]
  requestIm         


        
5条回答
  •  清歌不尽
    2021-01-31 05:28

    To get an exact square, you'll have to indicate that you want an exact size by passing options, like so:

        PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
    
        // No, really, we want this exact size    
        options.resizeMode = PHImageRequestOptionsResizeModeExact
    
        [[PHImageManager defaultManager]
                 requestImageForAsset:(PHAsset *)_asset
                           targetSize:CGSizeMake(160, 160)
                          contentMode:PHImageContentModeAspectFill
                              options:options
                        resultHandler:^(UIImage *result, NSDictionary *info) {
    
        // Happily, result is now a squared image
        imageView.image = result;
        }];
    

提交回复
热议问题