- (void)addImage
{
if (CGRectGetMaxX(addImageView.frame)>SCREEN_WIDTH-CGRectGetWidth(addImageView.frame)) {
[self ShowHUDTitle:@"只能添加三张图片" andDelay:];
return;
}
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 ://打开照相机
[self takePhoto];
break;
case ://打开相册
[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.03); // 图片的保存路径
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]; [imagePathList addObject:filePath]; addImageView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetMaxX(addImageView.frame), , SCREEN_WIDTH/, SCREEN_WIDTH/)];
addImageView.image = image;
addImageView.layer.borderWidth = ;
addImageView.layer.borderColor = [UIColor whiteColor].CGColor;
[self.view addSubview:addImageView]; CGSize size = [addressLabel.text sizeWithAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:]}];
addressLabel.frame = CGRectMake(, CGRectGetMaxY(addImageView.frame), size.width+, ); inputView.frame = CGRectMake(, CGRectGetMaxY(addressLabel.frame), SCREEN_WIDTH, SCREEN_HEIGHT-CGRectGetMaxY(addressLabel.frame)); }
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}

oc获得相册照片的更多相关文章

  1. Android7.0调用系统相机拍照、读取系统相册照片+CropImageView剪裁照片

    Android手机拍照.剪裁,并非那么简单 简书地址:[我的简书–T9的第三个三角] 前言 项目中,基本都有用户自定义头像或自定义背景的功能,实现方法一般都是调用系统相机–拍照,或者系统相册–选择照片 ...

  2. QQ空间相册照片批量导出

    QQ空间相册照片批量导出 先自己创建一个私人的单独的群,然后创建相册,上传照片来源从空间选图复制 复制完成后打开相册开始骚操作(两种方式) OK

  3. Android开发之获取相册照片和获取拍照照片

    在Android的开发过程中,我们可能会读取手机里面的照片或者通过相机拍摄获取照片,这是两种常用的获取图片的方式,在做项目过程中也会经常遇到,下面来介绍一下这两种获取方式.. 1.从本地相册获取照片: ...

  4. iOS UIWebView 中 js调用OC 打开相册 获取图片, OC调用js 将图片加载到html上

    线上html <!DOCTYPE html> <html> <head> <title>HTML中用JS调用OC方法</title> < ...

  5. Androd选取相册照片和拍照处理-android学习之旅(62)

    实现如下图所示效果 核心代码 -构建打开相册和拍照的Intent 拍照 File outputImage = new File(Environment.getExternalStorageDirect ...

  6. Android开发之获取相册照片和获取拍照照片二

    转至 http://blog.csdn.net/beyond0525/article/details/8940840 上一篇文章中讲解了照相机获取照片的时候遇到了可能取得的uri为null的状态,并给 ...

  7. 怎么SDCard上的获取相册照片

    private String getRealPathFromURI(Uri contentUri) { Cursor cursor = null; String result = contentUri ...

  8. cordova获取相册照片插件的使用方法:cordova-plugin-image-picker

    1. 添加插件:cordova plugin add cordova-plugin-image-picker 2.调用方法: 3.参考 : http://www.cnblogs.com/lyxy/p/ ...

  9. 【纯代码】Swift相册照片选择-支持单选或多选

    // // NAPublishAlbumTableViewController.swift //// // Created by on 2019/3/23. // Copyright © 2019年 ...

随机推荐

  1. java项目报junit 相关错误

    maven配置,java工程运行时需要把test测试相关移除

  2. vc++6.0各种报错合集(附:VC++6.0调出打印窗口的方法)

    背景: 由于VC++6.0对于现在的我来说,只是一个工具,暂时没有太多的时间分配到这块去深究它,由于不明其原理,因此也只是在此把错误积累下来,以备下次相同错误出现时能快速排除,节省时间. 正文 一.出 ...

  3. informatica中元数据管理

    摘自: http://blog.itpub.net/28690368/viewspace-766528/ informaica是一个很强大的ETL工具,WORKFLOW MANAGER负责对ETL调度 ...

  4. 原生态js获取节点的方法

    <input value="我是用id来获取值的" type="button" onclick="GetById()"/> &l ...

  5. int long 等基础类型在不同平台的大小

    转自http://www.cnblogs.com/yishuiliunian/archive/2011/03/18/1988244.html 上次腾讯面试,问我int和long分别几个字节,结果被鄙视 ...

  6. HDU 5047 Sawtooth(大数模拟)上海赛区网赛1006

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5047 解题报告:问一个“M”型可以把一个矩形的平面最多分割成多少块. 输入是有n个“M",现 ...

  7. 简单易懂的crontab设置工具集

    导读 在上一篇文章中,我介绍了crontab的配置文件以及如何设置定时任务,对于偶尔用一次crontab的同学而言,可能遗忘配置语法会很快,这里我向大家推荐几个在线设置crontab任务的网站. ge ...

  8. 2.2---找链表倒数第K个结点

    答案,注意,一种是递归,另一种是迭代,那么巧妙利用双指针: 迭代: public static LinkedListNode nthToLast(LinkedListNode head, int n) ...

  9. PyQt4控件失去焦点和获得焦点

    #QListView控件多选设置self.ui.listView.setSelectionMode(QAbstractItemView.ExtendedSelection) #初始化QListView ...

  10. 转:shell杀死指定名称的进程

    #!/bin/sh #根据进程名杀死进程 ] then echo "缺少参数:procedure_name" exit fi PROCESS=`|grep -v grep|grep ...