Last weekend, I decided to expand Coverflow to work with my entire photo album. This involved exploring the MusicLibrary and PhotoLibrary frameworks to find out how I could extract a complete set of albums and their pictures. The PLPhotoLibrary class proved to hold the key. With it, I could request an album list, and then build up a dictionary of photos that linked back from the image identifier to the album it came from.
id pl = [[PLPhotoLibrary alloc]
initWithPath:@"/var/mobile/Media/Photos"];
picList = [[NSMutableDictionary alloc] init];
int num = [[pl albums] count];
// Add every photo in the library
int i, j;
for (i = 0; i < num; i++)
{
album = [[pl albums] objectAtIndex:i];
id imgs = [album images];
for (j = 0; j < [imgs count]; j++) {
id imgid = [NSNumber numberWithInt:
[[imgs objectAtIndex:j] imageID]];
[picList setObject:album forKey:imgid];
}
}
Once the photos were all gathered, I could then pull back out each photo's album, and request a low-quality (thus memory-saving) CGImageRef.
// Image Data Source Method
- (void) coverFlow:(id)cf requestImageAtIndex: (int)idx quality: (int)q
{
id imgID = [[picList allKeys] objectAtIndex:idx];
id album = [picList objectForKey:imgID];
id img = [[album imageWithImageID:[imgID integerValue]]
createLowResolutionFullScreenCGImageRef];
[cfLayer setImage:img atIndex:idx type:q];
}
Together this allowed me to update my Coverflow sample to work with all onboard images. As you'll find when running this sample, I have not yet figured out some sort of matting scheme, so all the images are squashed (regardless of original aspect ratio) into a square.
The sample code is available as FullAlbum.m. You can also play with PhotoPhun, a simple non-coverflow application built over this library code.
Which version of the iPhone SDK is the PLPhotoLibrary class available in?
Hi,
I'm Nithin, currently a development trainee at a a company in India. I was just amazed by this blog.. Really i was searching for something similar to this. I had been given an assignment to create an application which imports all the photos from the iphone library to the app. And this blog made it simpler after my hardwork for over 2 weeks searching for a method to implementing it..