//
// 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-相机、相册的更多相关文章

  1. iOS开发小技巧--相机相册的正确打开方式

    iOS相机相册的正确打开方式- UIImagePickerController 通过指定sourceType来实现打开相册还是相机 UIImagePickerControllerSourceTypeP ...

  2. iOS 读取相册二维码,兼容ios7(使用CIDetector 和 ZXingObjC)

    ios从相册读取二维码,在ios8以上,苹果提供了自带的识别图片二维码的功能,这种方式效率最好,也是最推荐的,但是如果你的系统需要向下兼容ios7,就必须用其他方式. 这里我选择的是 ZXingObj ...

  3. Android 实现 IOS相机滑动控件

     IOS相比于Android,动画效果是一方面优势,IOS相机切换时滑动的动画很不错,看着是有一个3D的效果,而且变化感觉很自然.Android也可以通过Graphics下面的Camera可以实现3D ...

  4. ios从相册:摄像头中获取视频

    ios从相册/摄像头中获取视频 如何从相册中获取视频 使用的是一个和获取照片相同的类UIImagePickerController //相册中获取视频 - (IBAction)clickViedoOF ...

  5. iOS - 选取相册中iCloud云上图片和视频的处理

    关于iOS选取相册中iCloud云上图片和视频  推荐看:TZImagePickerController的源码,这个是一个非常靠谱的相册选择图片视频的库 .当然也可以自己写 如下遇到的问题 工作原因, ...

  6. iOS 相机和相册使用授权

    1.判断用户是否有权限访问相册 授权一次后,不在提示是否授权 #import <AssetsLibrary/AssetsLibrary.h> ALAuthorizationStatus a ...

  7. iOS相机权限、相册权限、定位权限判断

    1.判断用户是否有权限访问相册 #import <AssetsLibrary/AssetsLibrary.h> ALAuthorizationStatus author = [ALAsse ...

  8. IOS调用相机相册

    #import "SendViewController.h"  //只能打开,没有加载图片的代码,老代码,供参考 #import <MobileCoreServices/UT ...

  9. iOS调用相机,相册,上传头像

    一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...

  10. iOS调用相机,相册,上传头像 分类: ios技术 2015-04-14 11:23 256人阅读 评论(0) 收藏

    一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...

随机推荐

  1. 编译安装MariaDB-10.0.21

    一.源码编译安装gcc-5.1.0 1.下载gcc源码包 Download (HTTP): http://ftpmirror.gnu.org/gcc/gcc-5.2.0/gcc-5.2.0.tar.b ...

  2. 函数对象[条款18]---《C++必知必会》

    有时需要一些行为类似于函数指针的东西,但函数指针显得笨拙.危险而且过时(让我们承认这一点).通常最佳方式是使用函数对象(function object)取代函数指针. 与智能指针一样,函数对象也是一个 ...

  3. 在Windows上安装Elasticsearch 5.x

    在Windows上安装Elasticsearch 5.x 自己想学习Elasticsearch,但是又不懂Linux,按照同事给的Linux安装教程,也是搞不明白,于是想先在Windows上安装一下入 ...

  4. http协议中post方法发出请求

    package com.chinaums.szm.test.base.igoodful; import com.fasterxml.jackson.databind.ObjectMapper;impo ...

  5. The 15th UESTC Programming Contest Preliminary K - Kidd1ng Me? cdoj1565

    地址:http://acm.uestc.edu.cn/#/problem/show/1565 题目: Kidd1ng Me? Time Limit: 3000/1000MS (Java/Others) ...

  6. 由浅入深之Tensorflow(2)----logic_regression实现

    import tensorflow as tf import numpy as np from tensorflow.examples.tutorials.mnist import input_dat ...

  7. C/C++之Qt正则表达式

    引言 正则表达式(regular expression)就是用一个“字符串”来描述一个特征,然后去验证另一个“字符串”是否符合这个特征.比如 表达式“ab+” 描述的特征是“一个 'a' 和 任意个  ...

  8. [入坑系列] Mybatis 中$与#的区别

    1.理解 1 #是将传入的值当做字符串的形式,eg:select id,name,age from student where id =#{id},当前端把id值1,传入到后台的时候,就相当于 sel ...

  9. JCenter下载太慢?教你修改Maven仓库地址为国内镜像

    http://blog.csdn.net/biezhihua/article/details/49668605 转载自:http://www.yrom.net/blog/2015/02/07/chan ...

  10. Jquery编历数组

    <html> <head> <title>编历</title> <script type="text/javascript"& ...