IOS照相机的启动,图片的读取,存储demo
#import
@interface ViewController : UIViewController
@property (retain, nonatomic) IBOutlet UIImageView *imgV;
- (IBAction)openCamera:(id)sender;
- (IBAction)openPhotoLibrary:(id)sender;
- (IBAction)openSavedPhotoAlbum:(id)sender;
@end
#import "ViewController.h"
@implementation ViewController
@synthesize imgV;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[self setImgV:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (IBAction)openCamera:(id)sender
{
//UIImagePickerController 类方法,判断源是否可用 UIImagePickerController是一个图片挑选控制器 可以通过三种途径挑选图片。Camera、PhotoLibrary、SavedPhotoAlbum
BOOL hasCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];//判断照相机是否可用(是否有摄像头)
if(hasCamera == YES)
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
picker.allowsEditing = YES; //是否可编辑
[self presentModalViewController:picker animated:YES];
[picker release];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"你没有摄像头" delegate:nil cancelButtonTitle:@"ok!" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSLog(@"%@",info);
// {
// UIImagePickerControllerCropRect = "NSRect: {{-1, 320}, {1937, 1937}}";
// UIImagePickerControllerEditedImage = "";
// UIImagePickerControllerMediaMetadata = {
// DPIHeight = 72;
// DPIWidth = 72;
// Orientation = 6;
// "{Exif}" = {
// ApertureValue = "2.970853654340484";
// BrightnessValue = "2.246098001053075";
// ColorSpace = 1;
// DateTimeDigitized = "2012:09:20 11:47:12";
// DateTimeOriginal = "2012:09:20 11:47:12";
// ExposureMode = 0;
// ExposureProgram = 2;
// ExposureTime = "0.06666666666666667";
// FNumber = "2.8";
// Flash = 24;
// FocalLength = "3.85";
// ISOSpeedRatings = (
// 125
// );
// MeteringMode = 5;
// PixelXDimension = 2592;
// PixelYDimension = 1936;
// SceneType = 1;
// SensingMethod = 2;
// Sharpness = 2;
// ShutterSpeedValue = "3.911199862602335";
// SubjectArea = (
// 1295,
// 967,
// 699,
// 696
// );
// WhiteBalance = 0;
// };
// "{TIFF}" = {
// DateTime = "2012:09:20 11:47:12";
// Make = Apple;
// Model = "iPhone 4";
// Software = "5.1.1";
// XResolution = 72;
// YResolution = 72;
// };
// };
// UIImagePickerControllerMediaType = "public.image";
// UIImagePickerControllerOriginalImage = "";
// }
UIImage *image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
imgV.image = image;
//如果想把某个UIImage对象存储到默认相册,使用下面代码
//UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
[self dismissModalViewControllerAnimated:YES];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[self dismissModalViewControllerAnimated:YES];
}
- (IBAction)openPhotoLibrary:(id)sender //相册列表
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.delegate = self;
picker.allowsEditing = YES; //是否可编辑
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (IBAction)openSavedPhotoAlbum:(id)sender //默认相册
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.delegate = self;
picker.allowsEditing = YES; //是否可编辑
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)dealloc {
[imgV release];
[super dealloc];
}
@end
IOS照相机的启动,图片的读取,存储demo的更多相关文章
- [置顶] ios 一个不错的图片浏览分享框架demo
demo功能:一个不错的图片浏览分享框架demo.iphone6.1 测试通过.可以浏览图片,保存,微博分享到新浪,腾讯,网易,人人等. 注:(由于各个微博的接口有时候会有调整,不一定能分享成功.只看 ...
- iOS LaunchScreen设置启动图片 启动页停留时间
问题:想实现类似微信启动页一样 设置为一个整页面的图片 问题二:iOS启动页面怎样设置多停留一会 新建的iOS 项目启动画面默觉得LaunchScreen.xib 假设想实现一张图片作为启动页,例如以 ...
- iOS LaunchScreen设置启动图片,启动页停留时间
[新建的iOS 项目启动画面默认为LaunchScreen.xib] 如果想实现一张图片作为启动页,如下图
- iOS程序的启动图片图标规范
- iOS 8 Xcode6 设置Launch Image 启动图片
本人apem http://www.mamicode.com/info-detail-494411.html 如何设置App的启动图,也就是Launch Image? Step1 1.点击Image. ...
- iOS 8 Xcode6 设置Launch Image 启动图片<转>
Step1 1.点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image" 2.如图,右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以 ...
- 【转载】iOS 设置Launch Image 启动图片(适用iOS9)
Step1 1.点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image" 2.如图,右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以 ...
- iOS 添加启动图片
之前添加启动图片,一直都是通过添加LaunchImage来实现,见链接 http://www.cnblogs.com/jys509/p/4856068.html 这种方法,就需要给每个尺寸添加图片. ...
- react-native ios打包 、设置图标 启动图片
在这里只记录xcode 打包操作,申请证书操作,之前已经记录过了. https://www.cnblogs.com/hellovoidworld/p/4127576.html 参考了这篇文章,只是可 ...
随机推荐
- 上传文件插件dropzone的实例
html: <div class="field"> <div id="file" class="dropzone"> ...
- day_06 再谈编码
1. 小数据池(常量池) 1.id() 通过id()查询一个变量在内存中的地址 2.is和== 1.is 判断左右两端内存地址是否一致,如果返回值是TRUE,则可以判断这两个变量值是同一对象 2.== ...
- Hive 报错信息及解决方法
return code 2 为SQL报错. return code 1 一般为权限问题. 具体要看源码.
- Doxygen生成美丽注释文档(1):初体验
Chapter 1 - 准备工作 (Windows环境) 1.1 程序包下载 1. Doxygen * 源码: git clone https://github.com/doxygen/doxygen ...
- /proc/sys/net/ipv4/下各参数含义
net.ipv4.tcp_tw_reuse = 0 表示开启重用.允许将TIME-WAIT sockets重新用于新的TCP连接,默认为0,表示关闭 net.ipv4.tcp_tw_recycle = ...
- 数据库mysql--基础命令
客户端 一.登录和退出 1.登录 mysql -h server-ip -u usename -p 回车,然后会提示输入密码 2.退出:"quit;" | "exit;& ...
- VMware 虚拟机(linux)增加根目录磁盘空间
VMware 虚拟机(linux)增加根目录磁盘空间 今天查看学校的监控报修系统,不能访问了!!!系统运行很慢,用top命令查看发现内存使用率90%,用"df -h ”查看“/”目录 ...
- SEO--HTML meta标签总结
<!DOCTYPE html> <!-- 使用html5 doctype,不区分大小写--> <html lang="zh-CN"> <h ...
- Windows Store 应用中获取程序集版本号的方法
本文为个人博客备份文章,原文地址: http://validvoid.net/windows-store-app-get-assembly-version/ WinRT 中对反射做了很多限制,假设 W ...
- IIS_常见问题及解决方法
配置错误 在唯一密钥属性“value”设置为“default.aspx”时,无法添加类型为“add”的重复集合项 配置文件 \\*******\web\web.config web.config中 & ...