iOS 调用系统相册,调用系统照相机,调用系统相册,并且对照片进行剪裁
来源:互联网 发布:电路图制作软件下载 编辑:程序博客网 时间:2024/05/22 00:53
今天要修改上传头像,化验单的功能。上传头像可以从相册中选择照片上传,也可以拍照上传。从相册上传的时候,可以对照片进行剪裁。
调用系统的相册,或者照相机,需要用到UIImagePickerController,使用UIImagePickerController 需要有两个代理,分别是UIImagePickerControllerDelegate,和
UINavigationControllerDelegate。
UIImagePickerControllerSourceType是用来设置调用UIImagePickerController 的类型了,若果sourceType = UIImagePickerControllerSourceTypeCamera;是调用相机。如果imagePickerController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary; 是调用系统相册。
imagePickerController.allowsEditing=YES;//表示可以编辑对照片进行编辑,会多出来一个正方形的框。个人认为只针对照片有用。
#pragma UIActionSheetDelegateMethod-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ if(buttonIndex==0) { NSLog(@"拍照"); UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; picker1 = [[UIImagePickerController alloc] init];//初始化 picker1.delegate = self; picker1.allowsEditing = YES;//设置可编辑 picker1.sourceType = sourceType; [self presentViewController:picker1 animated:YES completion:nil]; } else if(buttonIndex==1) { NSLog(@"从手机相册选择"); imagePickerController=[[UIImagePickerController alloc]init]; imagePickerController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary; imagePickerController.delegate = self; imagePickerController.allowsEditing=YES; [self presentViewController:imagePickerController animated:YES completion:^{ }]; } else if(buttonIndex==2) { NSLog(@"取消"); }}
这里还有一个回调的方法-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info,见名知意。
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ if(picker==picker1) { UIImage *image=[info objectForKey:@"UIImagePickerControllerOriginalImage"];//picker1 是拍照,要把拍下的照片保存到相册里面。 UIImageWriteToSavedPhotosAlbum(image, self, nil, nil); UIImage* image1 = [info objectForKey: @"UIImagePickerControllerEditedImage"];//把编辑后的图片发送给Server imageData=UIImagePNGRepresentation(image1); NSString *img_data_str=[imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; [self httpSetUserPhotoRequest:img_data_str]; } else if(picker==imagePickerController) { UIImage* image1 = [info objectForKey: @"UIImagePickerControllerEditedImage"]; imageData=UIImagePNGRepresentation(image1); NSString *img_data_str=[imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength]; [self httpSetUserPhotoRequest:img_data_str]; } [self dismissViewControllerAnimated:YES completion:NULL]; }
0 0
- iOS 调用系统相册,调用系统照相机,调用系统相册,并且对照片进行剪裁
- 调用系统照相机 相册
- 调用系统照相机和相册
- IOS 调用系统相册或照相机tab按钮显示中文
- IOS 调用系统相册或照相机tab按钮显示中文
- android 调用系统照相机拍照后保存到系统相册
- 调用系统相册 Android
- 调用系统相册
- 调用系统相机相册
- 调用系统相册
- 调用系统相册,相机
- Camera调用系统相册
- android调用系统相册
- 调用系统相册
- 调用系统相机相册
- iOS调用系统照相机
- android 调用系统照相机拍照后剪裁
- iOS调用系统相册显示英文标题
- android 开源项目个人总结
- 彻底了解mysql int类型
- ZOJ-3682 E - Cup 3 DP+01背包
- 【源码】使用Unity在屏幕上画个框
- 机器智慧能否超越人类?三派专家观点
- iOS 调用系统相册,调用系统照相机,调用系统相册,并且对照片进行剪裁
- ubuntu设置固定IP
- java实现文件编码格式的转化
- SQL Server管理常用SQL语句
- 三次指数平滑法(Holt-Winters)
- 稳压电源(4) 滤波
- 美团网求上市,是否会重蹈拉手网的覆辙?
- Android的自动化测试三: Permission Denial: starting instrumentation ComponentInfo 问题的解决
- Hello,programer! 我的第一篇博客