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

    }];

 用以上的代碼去獲取圖片會出現模糊,不清晰的狀況。(明明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);
    }];

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM