从Photolibrary中提取图像我们使用UIImagePickerViewController和UIImagePickerControllerSourceTypePhotoLibrary进入Photolibrary并获取图像,现在我的问题如何获取保存在我的photoLibary中的图像数。
是否允许我将图像计数显示在我的应用程序中。
答案 0 :(得分:7)
是的,允许您使用以下方法获取所有图像: - 导入照片框架
#import <Photos/Photos.h>
-(void)getAllPhotosFromCamera
{
imageArray=[[NSArray alloc] init];
mutableArray =[[NSMutableArray alloc]init];
PHImageRequestOptions *requestOptions = [[PHImageRequestOptions alloc] init];
requestOptions.resizeMode = PHImageRequestOptionsResizeModeFast;
requestOptions.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
requestOptions.synchronous = true;
PHFetchResult *result = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
NSLog(@"%d",(int)result.count);
PHImageManager *manager = [PHImageManager defaultManager];
NSMutableArray *images = [NSMutableArray arrayWithCapacity:[result count]];
// assets contains PHAsset objects.
__block UIImage *ima;
for (PHAsset *asset in result)
{
// Do something with the asset
[manager requestImageForAsset:asset
targetSize:PHImageManagerMaximumSize
contentMode:PHImageContentModeDefault
options:requestOptions
resultHandler:^void(UIImage *image, NSDictionary *info)
{
ima = image;
[images addObject:ima];
}];
}
imageArray = [images copy];
[_cView reloadData];
}
答案 1 :(得分:1)
如果您想获得计数,那么使用照片框架,您可以获得这样的计数
PHFetchResult *allPhotosResult = [PHAsset fetchAssetsWithMediaType:PHAssetMediaTypeImage options:nil];
NSLog(@"count of All Photos from Moments in iOS8, or Camera Roll - %lu",(unsigned long)allPhotosResult.count);
也不要忘记导入Photos Framework
#import <Photos/Photos.h>
答案 2 :(得分:0)
在这里,您可以获得所有图像数量。它也包括所有相册和相机胶卷图像。
__block NSInteger intTotalCount=0;
// Get all Album list...
PHFetchResult *userAlbums = [PHAssetCollection fetchAssetCollectionsWithType:PHAssetCollectionTypeAlbum subtype:PHAssetCollectionSubtypeAny options:nil];
[userAlbums enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx1, BOOL *stop) {
PHFetchResult *assetsFetchResult = [PHAsset fetchAssetsInAssetCollection:collection options:nil];
intTotalCount+=assetsFetchResult.count;
}];
// Get image count from Camera Roll
PHFetchOptions *allPhotosOptions = [PHFetchOptions new];
allPhotosOptions.predicate = [NSPredicate predicateWithFormat:@"mediaType == %d ",PHAssetMediaTypeImage];
PHFetchResult *allPhotosResult = [PHAsset fetchAssetsWithOptions:allPhotosOptions];
intTotalCount+=allPhotosResult.count;
NSLog(@"%d",intTotalCount);