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调出
作者:老Zhan
出处:http://www.cnblogs.com/mybkn/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。