//
// ViewController.m
// IOS_0301_相册和相机
//
// Created by ma c on 16/3/1.
// Copyright © 2016年 博文科技. All rights reserved.
// #import "ViewController.h" @interface ViewController ()<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate> @property (nonatomic, strong) UIImageView *chooseImgView;
@property (nonatomic, strong) UIButton *btnOpenCamera; @end @implementation ViewController - (void)viewDidLoad {
[super viewDidLoad]; self.chooseImgView = [[UIImageView alloc] initWithFrame:CGRectMake(, , , )];
self.chooseImgView.backgroundColor = [UIColor cyanColor];
[self.view addSubview:self.chooseImgView];
self.btnOpenCamera = [UIButton buttonWithType:UIButtonTypeCustom];
[self.btnOpenCamera setFrame:CGRectMake(, , , )];
[self.btnOpenCamera setBackgroundColor:[UIColor redColor]];
[self.btnOpenCamera setTitle:@"相册相机" forState:UIControlStateNormal];
[self.view addSubview:self.btnOpenCamera]; [self.btnOpenCamera addTarget:self action:@selector(openCamera) forControlEvents:UIControlEventTouchUpInside];
}
/*
UIImagePickerController(图片拾取器)
能够根据不同的指令,选择开启相机或相册
ps:
1.使用图片拾取器时,实现两个协议
UIImagePickerControllerDelegate
UINavigationControllerDelegate
2.判断当前设备是否存在相机 */ - (void)openCamera
{
NSLog(@"打开相册"); UIActionSheet *actionSheeet = [[UIActionSheet alloc] initWithTitle:@"开启系统相机|相册" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:@"相机" otherButtonTitles:@"相册", nil]; [actionSheeet showInView:self.view]; } - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
switch (buttonIndex) {
case :
{
NSLog(@"相机");
//设置图片拾取器
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
//设置代理
imgPicker.delegate = self;
//设置图片拾取器类型
imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//是否允许图片编辑
imgPicker.allowsEditing = YES;
//唤醒相机
[self presentViewController:imgPicker animated:YES completion:nil];
}
break;
case :
{
NSLog(@"相册");
//设置图片拾取器
UIImagePickerController *imgPicker = [[UIImagePickerController alloc] init];
//设置代理
imgPicker.delegate = self;
//设置图片拾取器类型
imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//是否允许图片编辑
imgPicker.allowsEditing = YES;
//唤醒相机
[self presentViewController:imgPicker animated:YES completion:nil]; }
break; default:
break;
} } - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
//完成获取图片的操作
NSLog(@"%@",info);
//获取编辑后的图片
UIImage *chooseImage = [info objectForKey:@"UIImagePickerControllerEditedImage"];
NSString *imageName = [info objectForKey:@"UIImagePickerControllerReferenceURL"];
NSLog(@"%@",imageName); self.chooseImgView.image = chooseImage; //将图片从系统相册中取出,并保存到沙河中
NSString *homePath = [NSHomeDirectory() stringByAppendingPathComponent:@"/Documents"];
NSString *realPath = [homePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%d",arc4random()%]]; NSLog(@"%@",realPath);
[UIImageJPEGRepresentation(chooseImage, 1.0f) writeToFile:realPath atomically:YES]; [self dismissViewControllerAnimated:YES completion:nil]; } - (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

IOS-相机、相册的更多相关文章

  1. iOS开发小技巧--相机相册的正确打开方式

    iOS相机相册的正确打开方式- UIImagePickerController 通过指定sourceType来实现打开相册还是相机 UIImagePickerControllerSourceTypeP ...

  2. iOS 读取相册二维码,兼容ios7(使用CIDetector 和 ZXingObjC)

    ios从相册读取二维码,在ios8以上,苹果提供了自带的识别图片二维码的功能,这种方式效率最好,也是最推荐的,但是如果你的系统需要向下兼容ios7,就必须用其他方式. 这里我选择的是 ZXingObj ...

  3. Android 实现 IOS相机滑动控件

     IOS相比于Android,动画效果是一方面优势,IOS相机切换时滑动的动画很不错,看着是有一个3D的效果,而且变化感觉很自然.Android也可以通过Graphics下面的Camera可以实现3D ...

  4. ios从相册:摄像头中获取视频

    ios从相册/摄像头中获取视频 如何从相册中获取视频 使用的是一个和获取照片相同的类UIImagePickerController //相册中获取视频 - (IBAction)clickViedoOF ...

  5. iOS - 选取相册中iCloud云上图片和视频的处理

    关于iOS选取相册中iCloud云上图片和视频  推荐看:TZImagePickerController的源码,这个是一个非常靠谱的相册选择图片视频的库 .当然也可以自己写 如下遇到的问题 工作原因, ...

  6. iOS 相机和相册使用授权

    1.判断用户是否有权限访问相册 授权一次后,不在提示是否授权 #import <AssetsLibrary/AssetsLibrary.h> ALAuthorizationStatus a ...

  7. iOS相机权限、相册权限、定位权限判断

    1.判断用户是否有权限访问相册 #import <AssetsLibrary/AssetsLibrary.h> ALAuthorizationStatus author = [ALAsse ...

  8. IOS调用相机相册

    #import "SendViewController.h"  //只能打开,没有加载图片的代码,老代码,供参考 #import <MobileCoreServices/UT ...

  9. iOS调用相机,相册,上传头像

    一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...

  10. iOS调用相机,相册,上传头像 分类: ios技术 2015-04-14 11:23 256人阅读 评论(0) 收藏

    一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...

随机推荐

  1. Android中三种超实用的滑屏方式汇总(转载)

    Android中三种超实用的滑屏方式汇总   现如今主流的Android应用中,都少不了左右滑动滚屏这项功能,(貌似现在好多人使用智能机都习惯性的有事没事的左右滑屏,也不知道在干什么...嘿嘿),由于 ...

  2. 聚类之k-means

    1.介绍 k-means算法以k为参数(所期望的簇的个数),把n个对象分成k个簇(单层划分),用质心(数据点的平均值)定义簇的原型.使得簇内具有较高的相似度,而簇间的相似度较低. 通过聚类,我们能够发 ...

  3. Linux系统常用命令示例

    1.在跟下创建一个目录,目录的名字为data # mkdir /data2.在data目录里创建一个文件,文件名为yunjisuan.txt # touch /data/yunjisuan.txt3. ...

  4. Android 4.4 音量调节流程分析(一)

    最近在做Android Audio方面的工作,有需求是在调节Volume_Up_Key & Volume_Down_key时,Spearker or Headset每音阶的衰减变为3db左右. ...

  5. $ 一步一步学Matlab(2)——Matlab基本通用操作

    在上一篇中对Matlab做了一个初步的了解,本文继续来零距离亲身体验Matlab,来感受一下Matlab的一些基本.通用的操作. 命令行窗口 一打开Matlab就能看到命令行窗口,在我所用的这个精简版 ...

  6. 对于近阶段公司代码 review 小结

    来新公司,给公司的SDK review了一下.发现了不少小问题,在此总结一下. (我下面说明问题可能是很简单,但是搞清楚某些问题还是花了些时间的,大家引以为戒吧) 先谈谈处理的问题: 1.某天QA说有 ...

  7. Mysql主从架构报错-Fatal error: The slave I/O thread stops because master and slave have equal MySQL server UUIDs; these UUIDs must be different for replication to work...

    在搭建Mysql主从架构过程中,由于从服务器是克隆的主服务器系统,导致主从mysql uuid相同, Slave_IO无法启动,报错如下: The slave I/O thread stops bec ...

  8. CSS 图像透明/不透明

    CSS 图像透明/不透明 使用CSS很容易创建透明的图像. 注意:CSS Opacity属性是W3C的CSS3建议的一部分. 一.示例一:创建一个透明图像 CSS3中属性的透明度是 opacity. ...

  9. iframe跨页面调用函数

    在项目中难免会遇到这样一个问题就是页面引入了IFrame并且需要父页面调用子页面函数或者子页面需要调用父页面函数.比如说:现在有两个页面parent.html和child.html.其中parent. ...

  10. Sql Server数据库链接字符串参数说明

               DataSource,//要连接到的 SQL Server 实例的名称或网络地址              FailoverPartner,//在主服务器停机时要连接到的伙伴服务 ...