Iphone 从iOS4中的设备加载照片

Iphone 从iOS4中的设备加载照片,iphone,uiimage,ios4,photo,Iphone,Uiimage,Ios4,Photo,我想一次从PhotoAlbum加载UIImages的计数,并显示在UIView上。 在iOS3中,它可能类似于: NSString *file_path = @"/var/mobile/Media/DCIM/100APPLE/" NSArray *imageSource = [fileManager contentsOfDirectoryAtPath:file_path error:nil] ; UIImage *image = [UIImage imageWithContentsOfFi

我想一次从
PhotoAlbum
加载
UIImages
的计数,并显示在UIView上。 在iOS3中,它可能类似于:

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 ;
在iOS3中,这种方法是可行的! 但现在在iOS4中,我知道路径已更改为

@"/var/mobile/Media/PhotoData/100APPLE/"
imageSource可以解析为两种类型的文件:.BTH(全尺寸).THM(缩略图),但它不能 从
[UIImage imageWithContentsOfFile:XXX.BTH]

这个问题有什么解决办法吗?或者这种方法应该被苹果拒绝


非常感谢

我认为你不允许进入文件系统获取照片,你的应用程序将被彻底拒绝。您应该尝试以下方法:

-(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];
    }
}

当然,这不是您特别想要使用的代码,所以请根据您的需要修改它。

实际上,我没有找到更好的方法在自己的控制器中显示整个图像。 我调整流量以符合我的要求

 - (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];  
}

该方法在用户单击thumbnil时发生。如果要执行多选,我的解决方案是使用NSOperation来处理文件保存,但仍需要用户单击拇指nil。

顺便说一句,它可能需要在UIImagePNGRepresentation(图像)之后缩放照片图像,原始图像(1200x1600)几乎300Kb

使用这两种方法加载照片表单设备

-(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];
  }