PHImageManager 獲取圖片模糊

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);
 
}];

用以上的代碼去獲取圖片會出現(xiàn)模糊,不清晰的狀況。(明明options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat 設(shè)置為高清了)

其實坑就在于contentMode 寫成了self.view.bounds.size,如果需要獲取清晰的請設(shè)置為:PHImageManagerMaximumSize?;蛘邠Q一種讀取圖片的方法:

[[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);
}];
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容