objective c - To Get all Images from Photo Library in iphone -


i trying retrive images photo library & display in app using assetslibrary. got url path of photos don't know how photo through it.

my code follow:

 nsmutablearray* asseturldictionaries = [[nsmutablearray 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]]; nslog(@"result is:%@",result); nslog(@"asset urldictionary is:%@",asseturldictionaries); nsurl *url= (nsurl*) [[result defaultrepresentation]url]; [library assetforurl:url resultblock:^(alasset *asset) { [assetsp addobject:asset]; } failureblock:^(nserror *error){ nslog(@"test:fail"); } ]; } } }; nsmutablearray *assetgroups = [[nsmutablearray alloc] init]; void (^ assetgroupenumerator) ( alassetsgroup *, bool *)= ^(alassetsgroup *group, bool *stop){ nslog(@"hi"); if(group != nil) { [group enumerateassetsusingblock:assetenumerator]; [assetgroups addobject:group]; nslog(@"number of assets in group :%d",[group numberofassets]); } }; assetgroups = [[nsmutablearray alloc] init]; alassetslibrary *library = [[alassetslibrary alloc] init]; [library enumerategroupswithtypes:alassetsgroupall usingblock:assetgroupenumerator failureblock:^(nserror *error) {nslog(@"a problem occurred");}]; 

this code fetched elcimagepickercontroller example here modifications done simplification.

may you

[self.assetgroup enumerateassetsusingblock:^(alasset *result, nsuinteger index, bool *stop) { if(result == nil) return; uiimageview *assetimageview = [[uiimageview alloc] initwithframe:viewframes]; [assetimageview setcontentmode:uiviewcontentmodescaletofill]; [assetimageview setimage:[uiimage imagewithcgimage:[result thumbnail]]]; }]; 

happy coding :)

new answer

just use

[uiimage imagewithcgimage:[[asset defaultrepresentation] fullscreenimage]] 

to store image directly instead of storing asset @ time of storing asset in assetsp

just follow

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]]; nslog(@"result is:%@",result); nslog(@"asset urldictionary is:%@",asseturldictionaries); nsurl *url= (nsurl*) [[result defaultrepresentation]url]; [library assetforurl:url resultblock:^(alasset *asset) { //your line //[assetsp addobject:asset]; //my changed line store image directly assetsp [assetsp addobject:[uiimage imagewithcgimage:[[asset defaultrepresentation] fullscreenimage]]]; } failureblock:^(nserror *error){ nslog(@"test:fail"); } ]; } } }; 

new answer 1

try code store alasset data in mutable array

nsmutablearray *returnarray = [[nsmutablearray alloc] init]; for(alasset *asset in _assets) { nsmutabledictionary *workingdictionary = [[nsmutabledictionary alloc] init]; [workingdictionary setobject:[asset valueforproperty:alassetpropertytype] forkey:@"uiimagepickercontrollermediatype"]; [workingdictionary setobject:[uiimage imagewithcgimage:[[asset defaultrepresentation] fullscreenimage]] forkey:@"uiimagepickercontrolleroriginalimage"]; [workingdictionary setobject:[[asset valueforproperty:alassetpropertyurls] valueforkey:[[[asset valueforproperty:alassetpropertyurls] allkeys] objectatindex:0]] forkey:@"uiimagepickercontrollerreferenceurl"]; [returnarray addobject:workingdictionary]; 

and image in uiimageview this

nsdictionary *dict = [info objectatindex:i]; uiimageview *imageview = [[uiimageview alloc] initwithimage:[dict objectforkey:uiimagepickercontrolleroriginalimage]]; [imageview setcontentmode:uiviewcontentmodescaleaspectfit]; 

Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -