ios调用相册或相机上传图片
来源:互联网 发布:人工智能专业就业方向 编辑:程序博客网 时间:2024/04/29 16:52
先添加一个button用来点击进行上传,点击button触发button事件:
- (IBAction)choosePhoto:(id)sender{ UIActionSheet *choosePhotoActionSheet; //定义一个actionsheet进行选择 if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { choosePhotoActionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"choose_photo", @"") delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", @"") destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"take_photo_from_camera", @""), NSLocalizedString(@"take_photo_from_library", @""), nil]; } else { choosePhotoActionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"choose_photo", @"") delegate:self cancelButtonTitle:NSLocalizedString(@"cancel", @"") destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"take_photo_from_library", @""), nil]; } [choosePhotoActionSheet showInView:self.view]; [choosePhotoActionSheet release];}
UIImagePickerControllerSourceType的三种情况(develeper document的定义):
typedef NS_ENUM(NSInteger, UIImagePickerControllerSourceType) {
UIImagePickerControllerSourceTypePhotoLibrary,//用户自定义的图片库
UIImagePickerControllerSourceTypeCamera, //通过照相机获取的图片
UIImagePickerControllerSourceTypeSavedPhotosAlbum //系统的相片库
};
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{NSUInteger sourceType = 0; if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { switch (buttonIndex) { case 0: sourceType = UIImagePickerControllerSourceTypeCamera; break; case 1: sourceType = UIImagePickerControllerSourceTypePhotoLibrary; break; case 2: return; } } else { if (buttonIndex == 1) { return; } else { sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; } } UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];imagePickerController.delegate = self;imagePickerController.allowsEditing = YES; imagePickerController.sourceType = sourceType;[self presentModalViewController:imagePickerController animated:YES];}#pragma mark - UIImagePickerControllerDelegate//由picker中所获取到的info后,用于处理info的函数- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {[picker dismissModalViewControllerAnimated:YES];self.photo = [info objectForKey:UIImagePickerControllerEditedImage]; //photo为存放获取到的相片[self.photoButton setImage:self.photo forState:UIControlStateNormal]; //photobutton为存放上传相片的button}- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{[self dismissModalViewControllerAnimated:YES];}
- ios调用相册或相机上传图片
- iOS调用相册或相机图片
- 调用相机或相册上传图片到服务器
- iOS调用相册、相机、上传
- iOS - 调用相机相册的方法 + 上传图片
- iOS学习:调用相机和相册,选择图片上传
- 调用系统相机 或 相册 获得图片
- Android 调用相册或相机选择图片
- 点击图片调用相册或相机
- android 调用相机 相册 及图片上传
- iOS开发:相册或相机调用
- [IOS]从相册或相机获取图片
- iOS调用相册、相机、上传等问题
- iOS调用相册、相机、上传等问题
- iOS 相册 相机的调用及上传
- iOS调用相机,相册,上传头像
- iOS 调用相册/相机/图片压缩
- iOS调用相机 相册 选取图片
- Scintilla在WTL中的简易使用
- Service完全解析
- EmguCV在64位机上的几个问题处理办法
- 黑马程序员_张孝祥老师的银行调度面试题
- apt使用
- ios调用相册或相机上传图片
- UVa100 - The 3n + 1 problem
- HDU1828--Picture
- 架设VSFTP服务器
- hdu 3435 A new Graph Game (KM)
- 计算几何专项:UVa 10585
- android程序内存泄漏的原因和解决办法
- 黑马程序员_张孝祥老师的基础加强1
- libSVM在VC环境下移植