PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
options.synchronous = true;
options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
options.networkAccessAllowed = YES;
options.progressHandler = ^(double progress, NSError *error, BOOL *stop, NSDictionary *info) {
/*
Progress callbacks may not be on the main thread. Since we're updating
the UI, dispatch to the main queue.
*/
dispatch_async(dispatch_get_main_queue(), ^{
if(handler) handler(progress);
});
};
[[PHImageManager defaultManager] requestImageForAsset:asset targetSize:PHImageManagerMaximumSize contentMode:self.view.bounds.size options:options resultHandler:^(UIImage *result, NSDictionary *info) {
// Hide the progress view now the request has completed.
// Check if the request was successful.
if(manager) manager(result);
}];
用以上的代碼去擷取圖檔會出現模糊,不清晰的狀況。(明明options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat 設定為高清了)
其實坑就在于contentMode 寫成了self.view.bounds.size,如果需要擷取清晰的請設定為:PHImageManagerMaximumSize。或者換一種讀取圖檔的方法:
[[PHImageManager defaultManager] requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
UIImage * result = [UIImage imageWithData:imageData];
if(manager) manager(result);
}];
解決問題的能力很關鍵~(iOS開發交流群:219926126)