views:

176

answers:

3

Hi,guys. i want to load "amount of UIImages" from PhotoAlbum at a time and display on the UIView. in iOS3 ,it may like :

NSString *file_path = @"/var/mobile/Media/DCIM/100APPLE/" 
NSArray *imageSource = [fileManager contentsOfDirectoryAtPath:file_path error:nil] ; 

UIImage *image = [UIImage imageWithContentsOfFile:[imageSource objectAtIndex:index]] ;
if (!image) {
NSLog(@"load image fail : %@" ,[imageSource objectAtIndex:index]) ;
}
return image ;

and in iOS3, this method is work ! but now in iOS4 , i know the path have been changed to @"/var/mobile/Media/PhotoData/100APPLE/"

and imageSource can parse to 2 types file : .BTH(full size) .THM(thumbnail) ,but it can't read BTH from [UIImage imageWithContentsOfFile:XXX.BTH]

is there any solution for this problem ? or this method should be reject from Apple ?

Thanks a lot !

+1  A: 

I don't think you're allowed to go into the filesystem to get photos, your app will be rejected outright. You should try something like this:

-(IBAction)openAlbums {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        UIImagePickerController *UIPicker = [[UIImagePickerController alloc] init];
        UIPicker.allowsImageEditing = NO;
        UIPicker.delegate = self;
        UIPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        [self presentModalViewController:UIPicker animated:YES];
    }
    else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Error" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

Of course, this won't be the EXACT code you in particular will want to use, so just modify it to your needs.

esqew
A: 

Hi,

Did u get solution to iOS 4 ?? If you know the solution mail me no … i need display the whole images in photo library to my own controller ..

SDT
A: 

Actually ,i found no better way to display whole images in my own Controller. i adjust the flow to fit my requirement.

 - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage: (UIImage *)image editingInfo:(NSDictionary *)editingInfo{

 // Transform image to NSData
 NSData *imageData = UIImagePNGRepresentation(image);

 // Create your path with Customized file-name   
 NSString *paths=NSHomeDirectory();   
 NSString *filename=@"XXXX.png";
 NSString *save=[paths stringByAppendingPathComponent:filename];   

 [imageData writeToFile:save atomically:NO];   

 [picker dismissModalViewControllerAnimated:YES];  

}

The method occur when user clicked the thumbnil. if you want to perform multi-select, my solution is to use NSOperation to deal with file save and it still need user clicked the thumbnil.
by the way, it may need to scale the photo image after UIImagePNGRepresentation(image) ,the Original image(1200x1600) almost 300Kb

KaZa