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 ...
随机推荐
- sqlserver 2005/2008 导入超大sql文件
SQLCMD -E -dmaster -ic:\Scripts\create_db.sql 安装了Microsoft® SQL Server® 2008 R2 Native Client可用
- TWebBrowser静音
procedure TForm1.FormCreate(Sender: TObject); var hDSound: Cardinal; pDirectSoundCreate: Pointer ...
- 移动端打印输出内容以及网络请求-vconsole.js
今天,无意间从别人那里得知一个很好的js插件--vconsole.min.js,可以实现在移动端打印输出内容以及查看网络请求.下面记录使用方式. 1.下载vconsole.min.js插件 以下复制了 ...
- Linux系统——硬链接与软链接
文件属性软硬连接: 链接有两种,一种为硬链接(Hard Link),另一种为软链接或符号链接(Symbolic Link或Soft Link). 建立硬链接时,链接文件和被链接文件必须位于同一个文件系 ...
- 数据库(11)-- Hash索引和BTree索引 的区别
索引是帮助mysql获取数据的数据结构.最常见的索引是Btree索引和Hash索引. 不同的引擎对于索引有不同的支持:Innodb和MyISAM默认的索引是Btree索引:而Mermory默认的索引是 ...
- 【android】通过leakCanary找出程序内存泄露点
背景 内存泄露是咱新手比较头痛的问题,因为它不像崩溃,在开发环境可以根据提示的错误信息排查问题. 你都不知道咱的app是否哪个犄角旮旯藏着一个吞噬内存的黑洞. 排查android 内存泄露比较底层高端 ...
- weblogic控制台部署web项目图解
图解网址:http://jingyan.baidu.com/article/c74d6000650d470f6b595d72.html
- mysql-community-server安装完后不知道root密码
修改方法: service mysqld stop mysqld_safe --skip-grant-tables & mysql -u root use mysql; update user ...
- [BZOJ1117]救火站gas
Description 给你一棵树,现在要建立一些消防站,有以下要求: 1. 消防站要建立在节点上,每个节点可能建立不只一个消防站. 2. 每个节点应该被一个消防站管理,这个消防站不一定建立在该节点上 ...
- Spring IOC 源码解析(持续)
如何查看源码 Spring源码下载https://github.com/spring-projects/spring-framework/tags?after=v3.1.0.RC1 eclipse关联 ...