UI_UIImagePickerController(读取图片)
创建图片
#pragma mark - 创建 photoImageView
- (void)createphotoImageView
{
self.photoImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 70, 320, 390)];
self.photoImageView.backgroundColor = [UIColor magentaColor];
// 打开交互 实现手势轻拍
self.photoImageView.userInteractionEnabled = YES;
[self addSubview:self.photoImageView];
}
实现代理(3个)
@interface RootViewController () <UIActionSheetDelegate, UIImagePickerControllerDelegate, UINavigationControllerDelegate>
// 绑定手势
- (void)viewDidLoad {
[super viewDidLoad];
// 轻拍手势
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGRAction:)];
[self.rootView.photoImageView addGestureRecognizer:tapGR];
}
#pragma mark - 实现手势操作
- (void)tapGRAction:(UITapGestureRecognizer *)sender
{
NSLog(@"tap it");
// 底部弹出的控件
UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"请选择图片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"从相冊选取",@"拍照", nil];
// 在什么地方展示
[sheet showInView:self.rootView];
}
#pragma mark - 轻拍手势中 action 代理方法
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
NSLog(@"%ld", buttonIndex);
// 从相冊选取或拍照
if (actionSheet.firstOtherButtonIndex == buttonIndex) {
NSLog(@"相冊");
// 相冊是否可用
if ([UIImagePickerController isSourceTypeAvailable:(UIImagePickerControllerSourceTypePhotoLibrary)]) {
UIImagePickerController *imagePickerVC = [[UIImagePickerController alloc] init];
// 通过代理方法拿到图片
imagePickerVC.delegate = self;
// 能够对图片进行编辑(相应代理方法)
imagePickerVC.allowsEditing = YES;
// 指定 pickVC 从相冊选取
imagePickerVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// 模态推出
[self presentViewController:imagePickerVC animated:YES completion:nil];
}
} else if (buttonIndex == actionSheet.firstOtherButtonIndex + 1)
{
NSLog(@"拍照");
if ([UIImagePickerController isSourceTypeAvailable:(UIImagePickerControllerSourceTypeCamera)]) {
UIImagePickerController *imagePickerVC = [[UIImagePickerController alloc] init];
// 通过代理方法拿到图片
imagePickerVC.delegate = self;
// 能够对图片进行编辑(相应代理方法)
imagePickerVC.allowsEditing = YES;
// 指定 pickVC 从相机选取
imagePickerVC.sourceType = UIImagePickerControllerSourceTypeCamera;
// 模态推出
[self presentViewController:imagePickerVC animated:YES completion:nil];
}
}
}
#pragma mark - 实现代理方法(拿到图片)
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[picker dismissViewControllerAnimated:YES completion:nil];
UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
self.rootView.photoImageView.image = image;
}
#pragma mark - 取消按钮的代理方法
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
// 一般在 rightButton
[picker dismissViewControllerAnimated:YES completion:nil];
}
UI_UIImagePickerController(读取图片)的更多相关文章
- nodejs进阶(4)—读取图片到页面
我们先实现从指定路径读取图片然后输出到页面的功能. 先准备一张图片imgs/dog.jpg. file.js里面继续添加readImg方法,在这里注意读写的时候都需要声明'binary'.(file. ...
- HTML中上传与读取图片或文件(input file)----在路上(25)
input file相关知识简例 在此介绍的input file相关知识为: 上传照片及文件,其中包括单次上传.批量上传.删除照片.增加照片.读取图片.对上传的图片或文件的判断,比如限制图片的张数.限 ...
- nodeJS基础08:读取图片
1.读取图片 //server.js var http = require("http"); var readImage = require("./readImage&q ...
- opencv用imread( argv[1], 1)读取图片
显示一幅图:主要是运用功能:imread namedWindow imshowimread:从字面意思我们就可以看懂,用来读取图片的:namedWindow:显然,我们也可以看到这是用来命名窗口名称的 ...
- Servlet从本地文件中读取图片,并显示在页面中
import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpSer ...
- [OpenCV] 1、读取图片
>_<" 安装及配置请看http://www.cnblogs.com/zjutlitao/p/4042074.html >_<" 这篇是一个简单的在VS20 ...
- [转]asp.net mvc 从数据库中读取图片
本文转自:http://www.cnblogs.com/mayt/archive/2010/05/20/1740358.html 首先是创建一个类,继承于ActionResult,记住要引用Syste ...
- asp.net mvc 从数据库中读取图片的实现代码
首先是创建一个类,继承于ActionResult,记住要引用System.Web.Mvc命名空间,如下: public class ImageResult : ActionResult { publi ...
- 最蛋疼的bug:读取图片缩略图(一定要在相冊查看下形成缓存)
近期的一个连接服务端的应用.须要读取图片,一般供用户公布商品选择上传图片.初始的图片列表应该是缩略图.仅仅有确定了,才上传原图,OK不多说上代码 package edu.buaa.erhuo; imp ...
- C#(WinForm)上传图片保存到数据库和从数据库读取图片显示到窗体
//浏览图片 private void btnUp_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialo ...
随机推荐
- 【C++ Primer每日刷】之三 标准库 string 类型
标准库 string 类型 string 类型支持长度可变的字符串.C++ 标准库将负责管理与存储字符相关的内存,以及提供各种实用的操作.标准库string 类型的目的就是满足对字符串的一般应用. 与 ...
- Linux Kernel(Android) 加密算法总结(一)(cipher、compress、digest)
1. Linux内核支持哪些加密算法 ? 内核支持的加密算法非常多,包含: 对称加密算法.如AES,3DES. 对称password体制的发展趋势将以分组password为重点. 分组password ...
- mysql Access denied for user 'root'@'localhost' (using password: YES)
[现象说明] C/S程序远程訪问正常,本地訪问报下面异常 MySql.Data.MySqlClient.MySqlException (0x80004005): Authentication to h ...
- Android通过泛型简化findViewById类型转换
曾经老用findViewById,每次使用还得add cast一下今天看到一个视频(依据视频中使用的IDE判断,应该是几年前的视频了..),使用了一个方法,能够不用每次使用findViewById都去 ...
- 【iOS开发-68】APP下载案例:利用tableView自带的cell布局+缓存池cell复用时注意button状态的检查
(1)效果 (2)源码与资源下载 http://pan.baidu.com/s/1pJLo2PP (3)总结 --核心是利用UITableView里面自带的cell来制作样式同样的cell. 与之对应 ...
- angular 兼容ie11 ie11兼容
兼容一(new Date()用法) new Date('2018-01-01 00:00:00').getHours(); new Date('2018-01-01 00:00:00').getMin ...
- UVa512 追踪电子表格中的单元格
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- 编译安装FFmpeg 要支持xvid、x264、mp3、ogg、amr、faac
编译安装FFmpeg 要支持xvid.x264.mp3.ogg.amr.faac libfaac faac格式的编解码包libmp3lame mp3格式编解码包libopencore-am ...
- Codeforces 994B. Knights of a Polygonal Table
解题思路 将骑士按力量从小到大排序,到第i个骑士的时候,前面的i-1个骑士他都可以击败,找出金币最多的k个. 用multiset存金币最多的k个骑士的金币数,如果多余k个,则删除金币数最小的,直到只有 ...
- python模拟登陆知乎
---恢复内容开始--- 在完成前面的阶段的任务之后,我们现在已经能够尝试着去模拟登录一些网站了.在这里我们模拟登录一下知乎做一下实验.笔者在这里总共用了三天多的时间,下面给大家分享一下笔者是怎么一步 ...