QBImagePickerController 下ALAsset ,PHAsset转图片的使用

宋志学
2023-12-01

1.创建QBImagePickerController    

    QBImagePickerController *imagePickerController = [QBImagePickerController new];

    imagePickerController.delegate = self;

    imagePickerController.mediaType = QBImagePickerMediaTypeAny;

    //是否允许多选

    imagePickerController.allowsMultipleSelection = YES;

    imagePickerController.showsNumberOfSelectedAssets = YES;

    imagePickerController.minimumNumberOfSelection = 3;

    imagePickerController.maximumNumberOfSelection = 6;

    [imagePickerController.selectedAssets addObject:[PHAsset fetchAssetsWithOptions:nil].lastObject];

2.实现代理

#pragma mark - QBImagePickerControllerDelegate


- (void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets

{

//------------------------------ALAsset---------------------------------//

/*

   [self.imageMutableArray removeAllObjects];
    for (ALAsset * asset in assets) {
        ALAssetRepresentation *assetRep = [asset defaultRepresentation];
        CGImageRef imgRef = [assetRep fullResolutionImage];   //获取高清图片
        UIImage *img = [UIImage imageWithCGImage:imgRef  scale:assetRep.scale                        orientation:(UIImageOrientation)assetRep.orientation];
        [self.imageMutableArray addObject:img];
    }

*/

//------------------------------PHAsset---------------------------------//

    for (PHAsset *set in assets) {

        PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];

        options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;

        

        [[PHImageManager defaultManager] requestImageForAsset:set targetSize:[UIScreen mainScreen].bounds.size contentMode:PHImageContentModeAspectFit options:options resultHandler:^(UIImage *result, NSDictionary *info) {

            //设置图片

            [self.imageArr addObject:result];

        }];

    }

    [imagePickerController dismissViewControllerAnimated:YES completion:NULL];

}


- (void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController

{

    NSLog(@"Canceled");

    [imagePickerController dismissViewControllerAnimated:YES completion:NULL];

}

//推荐一个个人感觉比较好用的库 ----TZImagePickerController

github---https://github.com/banchichen/TZImagePickerController/


 类似资料: