系统提供的UIImagePickerController
1.从系统相册中读取
/*
判断选择的读取类型是否支持
UIImagePickerControllerSourceTypePhotoLibrary,普通相册
UIImagePickerControllerSourceTypeCamera, 镜头(拍照、录视频)
UIImagePickerControllerSourceTypeSavedPhotosAlbum(自己保存的图片)
*/
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
self.imagePC = [[UIImagePickerController alloc] init];
_imagePC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//相册操作由代理来监听 取消还是选择完成
_imagePC.delegate = self;
//展示相册
[self presentViewController:_imagePC animated:YES completion:nil];
}
2.拍照录视频
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePC = [[UIImagePickerController alloc] init];
_imagePC.delegate = self;
_imagePC.sourceType = UIImagePickerControllerSourceTypeCamera;
//图片 public.image
//视频 public.movie
_imagePC.mediaTypes = @[@"public.movie"];
[self presentViewController:_imagePC animated:YES completion:nil];
}
3.代理
读取图片或者视频 统一回调这个代理
系统相册 一次只能选取一张
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(@"%@", info);
// UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
// NSData *data = UIImagePNGRepresentation(image);
// NSUInteger byte = data.length/8;
// NSUInteger k = byte / 1024;
// NSUInteger m = k / 1024;
// NSLog(@"%ld", m);计算照片大小
}
//取消按钮被按了
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:nil];
}
4.将图片保存到系统相册
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
系统提供的UIImagePickerController的更多相关文章
- 如何在Windows Server 2008 R2没有磁盘清理工具的情况下使用系统提供的磁盘清理工具
今天,刚好碰到服务器C盘空间满的情况,首先处理了临时文件和有关的日志文件后空间还是不够用,我知道清理C盘的方法有很多,但今天只分享一下如何在Windows Server 2008 R2没有磁盘清理工具 ...
- iOS 动态下载系统提供的中文字体
使用系统提供的中文字体,既可避免版权问题,又可以减小应用体积 #pragma mark - 判断字体是否已经被下载 - (BOOL)isFontDownLoaded:(NSString *)fontN ...
- iOS系统提供开发环境下命令行编译工具:xcodebuild
iOS系统提供开发环境下命令行编译工具:xcodebuild[3] xcodebuild 在介绍xcodebuild之前,需要先弄清楚一些在XCode环境下的一些概念[4]: Workspace:简单 ...
- Swift - 访问通讯录联系人(使用系统提供的通讯录交互界面)
1,通讯录访问介绍 通讯录(或叫地址簿,电话簿)是一个数据库,里面储存了联系人的相关信息.要实现访问通讯录有如下两种方式: (1)AddressBook.framework框架 : 没有界面,通过代码 ...
- Android该系统提供的服务--Vibrator(振子)
Android该系统提供的服务--Vibrator(振子) --转载请注明出处:coder-pig Vibrator简单介绍与相关方法: watermark/2/text/aHR0cDovL2Jsb2 ...
- (原)SQL Server 系统提供功能的三个疑惑
本文目录列表: 1.SQL Server系统提供的部分疑惑概述2.系统函数调用时DEFAULT代替可选参数使用不统一3.队列字段列message_enqueue_time记录的是UTC日期时间 4.@ ...
- 选择排序法、冒泡排序法、插入排序法、系统提供的底层sort方法排序之毫秒级比较
我的代码: package PlaneGame;/** * 选择排序法.冒泡排序法.插入排序法.系统提供的底层sort方法排序之毫秒级比较 * @author Administrator */impo ...
- spring security 一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架
Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架.它提供了一组可以在Spring应用上下文中 配置的Bean,充分利用了Spring ...
- UIView封装动画--iOS利用系统提供方法来做转场动画
UIView封装动画--iOS利用系统提供方法来做转场动画 UIViewAnimationOptions option; if (isNext) { option=UIViewAnimationOpt ...
随机推荐
- Swift 面向对象
import Foundation class Hi{ func sayHi(){ print("HI jinpanpang") } } class Hello:Hi { var ...
- ref参数的用途
ref参数 能够将一个变量带入方法进行改变,改变完成后再将改变完成后的变量带出方法 ref参数要求在方法外必须为值赋值,而方法内可以不赋值 static void Main(string[] arr) ...
- C++中的struct与class继承方式
代码: #include <iostream> #include <cstdio> using namespace std; //class A{ struct A{ publ ...
- hdu 5188
it's a dp difficult problem 试想如果我们遇见这样一道题,: 有n道题目,每道题有一个得分v和用时t: 我们要得够w分:用时最少 怎么做?? 这是一个裸奔的01背包 如 ...
- OSG多屏显示问题
// testMultiScreen.cpp : Defines the entry point for the console application.// #include "stdaf ...
- 用jQuery的ajax请求一般处理程序返回json数据
1.web页面代码: 注意事项: dataType类型一定要写成json. 2.一般处理程序代码: 注意事项: ContentType类型写成"application/json"或 ...
- 关于一个小bug的修正
python初学者,非常喜欢虫师的文章. 练习时发现一个小bug,http://www.cnblogs.com/fnng/p/3782515.html 验证邮箱格式一题中,第三个x不允许有数字,但是测 ...
- $rootScope
参考地址 https://docs.angularjs.org/api/ng/type/$rootScope.Scope angular 的scope一般上都是有继承关系的,也就是说可以通过原型访问到 ...
- cf E. Valera and Queries
http://codeforces.com/contest/369/problem/E 题意:输入n,m; n 代表有多少个线段,m代表有多少个询问点集.每一个询问输出这些点的集合所占的线段的个数. ...
- TVS_压敏电阻等保护类器件的布局问题
世上本没有垃圾,垃圾都是放错了位置的资源. 对于电路来说,保护器件就是其保护作用的关键资源,但如果放错了位置,它就是垃圾:甚至不仅是垃圾,而还可能成为祸害. 由最近承接的几起电路原理图审核项目来看,触 ...