- (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. HDOJ 3709 Balanced Number

    数位DP... Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java ...

  2. OC第二节 —— NSString和NSMutableString

    1.为什么需要NSString对象        答:在OC中创建字符串时,一般不使用C的方法,    因为C将字符串作为字符数组,所以在操作时会有很多不方便的地方,    在Cocoa中NSStri ...

  3. 2015多校1006.First One

    First One Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  4. .net的一些新语法的整理

    using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...

  5. linux之samba与linux权限

    当linux的文件夹或文件为用户或root时,则在window上共享出来的samba是不能进行修改的,当samba设置为 [share]path = /home#available = yes#bro ...

  6. CodeForces 615B Longtail Hedgehog

    题目: http://codeforces.com/problemset/problem/615/B 题意:题目描述很复杂,但实际上很简单.大意就是连续的几个点组成尾巴,要求尾巴的长度乘以尾巴终点的分 ...

  7. 全架构PaaS TAE 2.0的Docker实践

    推荐链接: http://www.infoq.com/cn/news/2015/07/paas-tae-docker

  8. ajax验证登录注册

    <form id="form1" onsubmit="return false;"> <table id="login-table& ...

  9. HDU 5071 Chat(2014鞍山赛区现场赛B题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5071 解题报告:一个管理聊天窗口的程序,一共有八种操作,然后要注意的就是Top操作只是把编号为u的窗口 ...

  10. Unity手游之路<七>角色控制器

    Unity手游之路<七>角色控制器 我们要控制角色的移动,可以全部细节都由自己来实现.控制角色模型的移动,同时移动摄影机,改变视角.当然Unity也提供了一些组件,可以让我们做更少的工作, ...