读书人

获取系统相本中图片的方法

发布时间: 2012-08-25 10:06:20 作者: rapoo

获取系统相册中图片的方法
原文地址:获取系统相册中图片的方法
http://www.aisidachina.com/forum/viewthread.php?tid=244

定义一个按钮连接以下方法:

- (IBAction)selectExistingPicture {    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])         {        UIImagePickerController *picker = [[UIImagePickerController alloc] init];        picker.delegate = self;        picker.allowsImageEditing = YES;        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;        [self presentModalViewController:picker animated:YES];        [picker release];    }    else {        UIAlertView *alert = [[UIAlertView alloc]                               initWithTitle:@"访问图片库错误"                               message:@""                               delegate:nil                               cancelButtonTitle:@"OK!"                               otherButtonTitles:nil];        [alert show];        [alert release];    }}


再调用以下委托:
#pragma mark UIImagePickerControllerDelegate- (void)imagePickerController:(UIImagePickerController *)picker         didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {        imageView.image = image;        //imageView为自己定义的UIImageView                    [picker dismissModalViewControllerAnimated:YES];    }

读书人网 >移动开发

热点推荐