问题描述
我想在 uicollectionview 中显示从设备到我的应用程序的所有图像.并且想要从 uicollectionview 中选择多个图像.我看过很多节目.
I want to show all images from device to my app in uicollectionview.and want to select multiple images from uicollectionview. I have watched numbers of programs.ELCImagePickerController
but i cant get it correctly.please help me...thank you
this links works fine...Multi-Select ImagePickerbut how can i get selected images into an array from button Done..
When I press Done button image shown in array like this....
<UIImage: 0x7fca78772510>, {485, 303}
so, how can i get this image in my collection view.. help me guys....
Get all image from gallery
View Controller header(.h) file..
#import <UIKit/UIKit.h>
#include <AssetsLibrary/AssetsLibrary.h>
@interface getPhotoLibViewController : UIViewController
{
ALAssetsLibrary *library;
NSArray *imageArray;
NSMutableArray *mutableArray;
}
-(void)allPhotosCollected:(NSArray*)imgArray;
@end
implementation file
declare global count variable as
static int count=0;
@implementation getPhotoLibViewController
-(void)getAllPictures
{
imageArray=[[NSArray alloc] init];
mutableArray =[[NSMutableArray alloc]init];
NSMutableArray* assetURLDictionaries = [[NSMutableArray alloc] init];
library = [[ALAssetsLibrary alloc] init];
void (^assetEnumerator)( ALAsset *, NSUInteger, BOOL *) = ^(ALAsset *result, NSUInteger index, BOOL *stop) {
if(result != nil) {
if([[result valueForProperty:ALAssetPropertyType] isEqualToString:ALAssetTypePhoto]) {
[assetURLDictionaries addObject:[result valueForProperty:ALAssetPropertyURLs]];
NSURL *url= (NSURL*) [[result defaultRepresentation]url];
[library assetForURL:url
resultBlock:^(ALAsset *asset) {
[mutableArray addObject:[UIImage imageWithCGImage:[[asset defaultRepresentation] fullScreenImage]]];
if ([mutableArray count]==count)
{
imageArray=[[NSArray alloc] initWithArray:mutableArray];
[self allPhotosCollected:imageArray];
}
}
failureBlock:^(NSError *error){ NSLog(@"operation was not successfull!"); } ];
}
}
};
NSMutableArray *assetGroups = [[NSMutableArray alloc] init];
void (^ assetGroupEnumerator) ( ALAssetsGroup *, BOOL *)= ^(ALAssetsGroup *group, BOOL *stop) {
if(group != nil) {
[group enumerateAssetsUsingBlock:assetEnumerator];
[assetGroups addObject:group];
count=[group numberOfAssets];
}
};
assetGroups = [[NSMutableArray alloc] init];
[library enumerateGroupsWithTypes:ALAssetsGroupAll
usingBlock:assetGroupEnumerator
failureBlock:^(NSError *error) {NSLog(@"There is an error");}];
}
-(void)allPhotosCollected:(NSArray*)imgArray
{
//write your code here after getting all the photos from library...
NSLog(@"all pictures are %@",imgArray);
}
@end
Use getAllPicture method to get photos from photo library.
OR You can have a look at this blog http://mutiselectimagepicker.blogspot.in/2014/08/imageselect-to-allow-multiple-selection.html
这篇关于从设备获取所有图像并将其显示在 uicollectionview 中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!