iphone:使用UIImagePickerController从IPhone照片库或照相机获取图像

from: 使用UIImagePickerController从IPhone照片库或照相机获取图像

使用UIimagePickerController选取照片库操作十分简单:

在对应响应中

UIImagePickerController * picker = [[UIImagePickerController alloc] init];  

picker.delegate = self;  //控制器当然要遵循响应的delegate协议

picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; //指定picker的资源,有三种

                                                                                                   //enum { UIImagePickerControllerSourceTypePhotoLibrary,

                                   //      UIImagePickerControllerSourceTypeCamera,

                                   //     UIImagePickerControllerSourceTypeSavedPhotosAlbum }

    [selfpresentModalViewController:picker animated:YES];  //显示picker view

 

在delegate方法中:

-(void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{

  //info: A dictionary containing the original image and the edited image, if an image was picked; or a filesystem URL for the movie, if a movie was picked

    [picker dismissModalViewControllerAnimated:YES];  //让其消失

  imageView.image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];

}

 

NSString *const UIImagePickerControllerMediaType;
NSString *const UIImagePickerControllerOriginalImage;
NSString *const UIImagePickerControllerEditedImage;
NSString *const UIImagePickerControllerCropRect;
NSString *const UIImagePickerControllerMediaURL;
NSString *const UIImagePickerControllerReferenceURL;
NSString *const UIImagePickerControllerMediaMetadata;

RootViewController - tableView:cellForRowAtIndexPath - Load image from assetsLibrary

Using AssetsLibrary Framework loading images too slow

 

补充:ipad的不能调出UIImagePickerController,需要通过PopOver调出

posted on 2012-06-02 16:47  老Zhan  阅读(1446)  评论(0编辑  收藏  举报