iOS软件开发 获取相册图片或照相
来源:互联网 发布:pdm软件排名 编辑:程序博客网 时间:2024/05/21 14:06
从相册获取相片或者照相需要实现UIImagePickerControllerDelegate, UINavigationControllerDelegate这两个协议,下面是具体的实现方法
- (void)addImage{ UIActionSheet *actionsheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles: @"打开照相机", @"从手机相册获取",nil]; [actionsheet showInView:self.view];}- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{ if (buttonIndex == actionSheet.cancelButtonIndex) { } switch (buttonIndex) { case 0://打开照相机 [self takePhoto]; break; case 1://打开相册 [self localPhoto]; break; default: break; }}-(void)takePhoto//打开相机{ UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) { UIImagePickerController *picker = [[UIImagePickerController alloc]init]; picker.delegate = self; picker.allowsEditing = YES; picker.sourceType = sourceType; [self presentViewController:picker animated:YES completion:nil]; }}-(void)localPhoto//本地相册{ UIImagePickerController *picker = [[UIImagePickerController alloc]init]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; picker.allowsEditing = YES; [self presentViewController:picker animated:YES completion:nil];}-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{ NSString *type = [info objectForKey:UIImagePickerControllerMediaType]; // 当选择的类型是图片 if ([type isEqualToString:@"public.image"]) { // 把图片转化为NSData UIImage *image = info[UIImagePickerControllerEditedImage]; NSData *data = UIImageJPEGRepresentation(image, 0.1); // 图片的保存路径 NSString *documentsPath = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]; NSFileManager *manager = [NSFileManager defaultManager]; // 将刚刚转化的图片放到沙盒中 并保存为png [manager createDirectoryAtPath:documentsPath withIntermediateDirectories:YES attributes:nil error:nil]; NSString *imageName = [NSString stringWithFormat:@"/%@.png",[NSDate date]]; [manager createFileAtPath:[documentsPath stringByAppendingString:[NSString stringWithFormat:@"%@",imageName]] contents:data attributes:nil]; //得到选择后沙盒的路径 filePath = [[NSString alloc]initWithFormat:@"%@%@",documentsPath,imageName]; NSLog(@"%@",filePath); [picker dismissViewControllerAnimated:YES completion:nil]; }- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{ [picker dismissViewControllerAnimated:YES completion:nil]; }
0 0
- iOS软件开发 获取相册图片或照相
- IOS调用相册和照相获取图片
- iOS 8 照相或从相册选取、
- [IOS]从相册或相机获取图片
- Android知识点3-通过照相或相册更改图片
- iOS开发 使用UIImagePicker从相机或相册获取图片并裁剪
- android照相、相册获取图片剪裁报错的解决方案
- android照相、相册获取图片剪裁报错的解决方法
- android照相、相册获取图片剪裁报错的解决方案
- android照相、相册获取图片剪裁报错的解决方法
- iOS 从相机或相册获取图片并裁剪
- iOS 从相机或相册获取图片并裁剪
- iOS 从相机或相册获取图片并裁剪
- [IOS]iphone从相册或相机获取图片
- 获取相册图片或拍照
- 获取相册图片 照相图片 并剪裁 完美适配6.0版本的相册错误
- iOS从相机或相册获取图片并裁剪,再获取裁剪后的图片
- iOS获取相册图片视频
- 自定义 View 3d翻转动画 android
- OpenWRT安装完后make menuconfig失败
- MVC中的AOP思想——Filter
- notepad++快捷键
- 2015华为Word Maze 是一个网络小游戏,你需要找到以字母标注的食物
- iOS软件开发 获取相册图片或照相
- UNIX 高手的 10 个习惯 http://www.ibm.com/developerworks/cn/aix/library/au-badunixhabits.html
- Lua动态生成代码
- java文件图标变成空心J
- netstate 与 tcpdump
- SweepGradient扫描渲染
- hdu5443 The Water Problem(长春网络赛)
- 我的Java Web作业---百度音乐网站
- 最少次数确定出不同的那个球