IOS-相机、相册
//
// 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-相机、相册的更多相关文章
- iOS开发小技巧--相机相册的正确打开方式
iOS相机相册的正确打开方式- UIImagePickerController 通过指定sourceType来实现打开相册还是相机 UIImagePickerControllerSourceTypeP ...
- iOS 读取相册二维码,兼容ios7(使用CIDetector 和 ZXingObjC)
ios从相册读取二维码,在ios8以上,苹果提供了自带的识别图片二维码的功能,这种方式效率最好,也是最推荐的,但是如果你的系统需要向下兼容ios7,就必须用其他方式. 这里我选择的是 ZXingObj ...
- Android 实现 IOS相机滑动控件
IOS相比于Android,动画效果是一方面优势,IOS相机切换时滑动的动画很不错,看着是有一个3D的效果,而且变化感觉很自然.Android也可以通过Graphics下面的Camera可以实现3D ...
- ios从相册:摄像头中获取视频
ios从相册/摄像头中获取视频 如何从相册中获取视频 使用的是一个和获取照片相同的类UIImagePickerController //相册中获取视频 - (IBAction)clickViedoOF ...
- iOS - 选取相册中iCloud云上图片和视频的处理
关于iOS选取相册中iCloud云上图片和视频 推荐看:TZImagePickerController的源码,这个是一个非常靠谱的相册选择图片视频的库 .当然也可以自己写 如下遇到的问题 工作原因, ...
- iOS 相机和相册使用授权
1.判断用户是否有权限访问相册 授权一次后,不在提示是否授权 #import <AssetsLibrary/AssetsLibrary.h> ALAuthorizationStatus a ...
- iOS相机权限、相册权限、定位权限判断
1.判断用户是否有权限访问相册 #import <AssetsLibrary/AssetsLibrary.h> ALAuthorizationStatus author = [ALAsse ...
- IOS调用相机相册
#import "SendViewController.h" //只能打开,没有加载图片的代码,老代码,供参考 #import <MobileCoreServices/UT ...
- iOS调用相机,相册,上传头像
一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...
- iOS调用相机,相册,上传头像 分类: ios技术 2015-04-14 11:23 256人阅读 评论(0) 收藏
一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...
随机推荐
- __new__方法以及TypeError: object() takes no parameters的处理
一些python书或博客将类中的__init__方法称为构造函数,而实际上这种说法是不严格的,因为创建实例的方法是__new__,实例初始化的方法是__init__.__new__方法会返回一个实例, ...
- u-boot.cfg转eclipse_xml小脚本
手动复制粘贴版本 cat u-boot.cfg | awk '{if(length($3)){$3 = substr($0, length($1)+length($2)+3); gsub(" ...
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016) B - Bribing Eve
地址:http://codeforces.com/gym/101174/attachments 题目:pdf,略 思路: 把每个人的(x1,x2)抽象成点(xi,yi). 当1号比i号排名高时有==& ...
- Android如何定制一个下拉刷新,上滑加载更多的容器
前言 下拉刷新和上滑加载更多,是一种比较常用的列表数据交互方式. android提供了原生的下拉刷新容器 SwipeRefreshLayout,可惜样式不能定制. 于是打算自己实现一个专用的.但是下拉 ...
- Win10应用《纸书科学计算器》更新啦!
<纸书科学计算器>在2016年8月拿了计算机设计大赛国家一等奖,现在仍记得我在答辩时还给评委们普及了一波UWP平台的知识.受此鼓励,这款应用也不会停下更新的脚步^_^.最近从1.9小幅升级 ...
- 有关string stringbuff stringbuild 的区别
string stringbuff stringbuild的执行效率: stringbuild>stringbuff>string String类是不可变类,任何对String的改变都会 ...
- Python3.x:获取代理ip以及使用
Python3.x:获取代理ip以及使用 python爬虫浏览器伪装 #导入urllib.request模块 import urllib.request #设置请求头 headers=("U ...
- 20145312《Java第一次实验报告》
20145312<Java第一次实验报告> Java开发环境的熟悉(Windows+Idea) 一.实验内容 使用Idea编辑.编译.运行.调试Java程序. 使用JDK编译.运行简单的J ...
- 2_jenkins_git创建创建及项目构建
确保jenkins服务正常工作 进入WEB界面 查看git插件是否正常安装 "管理系统" --> "管理插件" "可选插件" 然后找到 ...
- python-内置函数及捕获异常
eval:把字符串转换成有效表达式 repr:把有效表达式转换成字符串 round(...) round(number[, ndigits]) -> number Round a num ...