如何使用IOS 9上的UIImagePicker结果URL和PHAsset从媒体库加载图像

时间:2016-04-22 12:01:30

标签: ios objective-c iphone phasset

PHImageManager *manager = [PHImageManager defaultManager];
for (PHAsset *asset in result) {        
    [manager requestImageForAsset:asset
                       targetSize:PHImageManagerMaximumSize
                      contentMode:PHImageContentModeDefault
                          options:requestOptions
                    resultHandler:^void(UIImage *image, NSDictionary *info) {
                        _profileImageView.image = image;

                        //[images addObject:_profileImageView];
                    }];    
}

它不适合我

1 个答案:

答案 0 :(得分:0)

首先让requestoptions赞成,

self.requestOptions = [[PHImageRequestOptions alloc] init];
self.requestOptions.resizeMode   = PHImageRequestOptionsResizeModeExact;
self.requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;

// this one is key
self.requestOptions.synchronous = true;

如果数组中有多个资源填充了PHAsset对象,则添加以下代码:

self.assets = [NSMutableArray arrayWithArray:assets];
PHImageManager *manager = [PHImageManager defaultManager];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:[assets count]];

// assets contains PHAsset objects.
 __block UIImage *ima;

for (PHAsset *asset in self.assets) {
// Do something with the asset

[manager requestImageForAsset:asset
                   targetSize:PHImageManagerMaximumSize
                  contentMode:PHImageContentModeDefault
                      options:self.requestOptions
                resultHandler:^void(UIImage *image, NSDictionary *info) {
                    ima = image;

                    [images addObject:ima];
                }];


}

现在images数组包含uiimage格式的所有图片。

希望这会有所帮助:)