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 ...
随机推荐
- JAVAEE之--------过滤器设置是否缓存(Filter)
在网页中.每次的client訪问server.有部分不用反复请求.如有些图片,视频等就没有必要每次都请求,这样会让server增大工作量.为了防止这样.我们採用过滤器来设置client是都缓存. 參考 ...
- DOMContentLoaded事件<zz>
今天查看百度空间源代码,发现多了个util.js文件,打开看看.里面里面定义了addDOMLoadEvent.这是干什么用的? 仔细查看代码,发现在Mozilla添加了DOMContentLoaded ...
- hdu2476String painter (区间DP)
Problem Description There are two strings A and B with equal length. Both strings are made up of low ...
- 【NOI 2002】 银河英雄传说
[题目链接] https://www.luogu.org/problemnew/show/P1196 [算法] 并查集 [代码] #include<bits/stdc++.h> using ...
- HIT Software Construction Lab 3
2019年春季学期 计算机学院<软件构造>课程 Lab 3实验报告 姓名 刘帅 学号 班号 1703008 电子邮件 1609192321@qq.com 手机号码 目录 1 实验目标概 ...
- 5.文件I/O
1 C标准函数与系统函数的区别 文件的结构体: 1.1 I/O缓冲区 每一个FILE文件流都有一个缓冲区buffer,默认大小8192Byte. 1.2 效率 文件缓冲区会降低效率.这里提供缓冲区主要 ...
- 2.linux系统命令详解
1 shell shell:命令解释器,根据输入的命令执行相应命令. 1.1 shell家族 察看当前系统下有哪些shell: cat /etc/shells 察看当前系统正在使用的shell ech ...
- Ubuntu16.04下沙盒数据导入到 Neo4j 数据库(图文详解)
不多说,直接上干货! 参考博客 http://blog.csdn.net/u012318074/article/details/72793914 (表示感谢) 前期博客 Neo4j沙盒实验申请过 ...
- 互联网智能门锁,手机蓝牙APP成为首选
随着互联网门锁在行业中的普及,大家越加关注到门锁的实施和维护成本.我们在互联网智能门锁的调研中发现,网关联网的智能门锁,使用时需要依赖房间内的宽带上网线路,而断线后客户反馈问题较多.据某家分散式公寓的 ...
- JAVA 日期工具类的总结
一般,在项目中,我们会会经常使用到日期的各种方式的处理,在各个业务逻辑操作中,都需要相关的日期操作,因此,实现项目中的日期工具类的提出,还是十分重要的,下面,就项目中常用到的日期的相关操作方式,做了一 ...