i want to load count 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:[i开发者_如何学运维mageSource 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 !
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.
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
use these two method for load your photo form device.
-(void)takePhoto:(id)sender
{
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//Use camera if device has one otherwise use photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
[imagePicker setSourceType:UIImagePickerControllerSourceTypeCamera];
}
else
{
[imagePicker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
}
[imagePicker setDelegate:self];
//Show image picker
[self presentModalViewController:imagePicker animated:YES];
//Modal so we wait for it to complete
[imagePicker release];
}
//********** RECEIVE PICTURE **********
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//Get image
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
//Display in ImageView object (if you want to display it
[playerImage setImage:image];
//Take image picker off the screen (required)
[self dismissModalViewControllerAnimated:YES];
}
精彩评论