#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的更多相关文章

  1. [置顶] ios 一个不错的图片浏览分享框架demo

    demo功能:一个不错的图片浏览分享框架demo.iphone6.1 测试通过.可以浏览图片,保存,微博分享到新浪,腾讯,网易,人人等. 注:(由于各个微博的接口有时候会有调整,不一定能分享成功.只看 ...

  2. iOS LaunchScreen设置启动图片 启动页停留时间

    问题:想实现类似微信启动页一样 设置为一个整页面的图片 问题二:iOS启动页面怎样设置多停留一会 新建的iOS 项目启动画面默觉得LaunchScreen.xib 假设想实现一张图片作为启动页,例如以 ...

  3. iOS LaunchScreen设置启动图片,启动页停留时间

    [新建的iOS 项目启动画面默认为LaunchScreen.xib] 如果想实现一张图片作为启动页,如下图

  4. iOS程序的启动图片图标规范

     

  5. iOS 8 Xcode6 设置Launch Image 启动图片

    本人apem http://www.mamicode.com/info-detail-494411.html 如何设置App的启动图,也就是Launch Image? Step1 1.点击Image. ...

  6. iOS 8 Xcode6 设置Launch Image 启动图片<转>

    Step1 1.点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image" 2.如图,右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以 ...

  7. 【转载】iOS 设置Launch Image 启动图片(适用iOS9)

    Step1 1.点击Image.xcassets 进入图片管理,然后右击,弹出"New Launch Image" 2.如图,右侧的勾选可以让你选择是否要对ipad,横屏,竖屏,以 ...

  8. iOS 添加启动图片

    之前添加启动图片,一直都是通过添加LaunchImage来实现,见链接 http://www.cnblogs.com/jys509/p/4856068.html 这种方法,就需要给每个尺寸添加图片. ...

  9. react-native ios打包 、设置图标 启动图片

    在这里只记录xcode 打包操作,申请证书操作,之前已经记录过了. https://www.cnblogs.com/hellovoidworld/p/4127576.html  参考了这篇文章,只是可 ...

随机推荐

  1. Photoshop在网页设计中的应用与方法

    1.图像局部截取和图像尺寸调整 做网页设计时经常要用到的某张图像一部分,这就需要截取图像的局部.图像局部截取的方法很多,但使用Photoshop操作起来更方便.具体操作步骤如下: (1)在Photos ...

  2. saltstack一键部署高可用

    一健推送apache [root@server1 minions]# cd /etc/salt/ [root@server1 salt]# vim master [root@server1 salt] ...

  3. linu samba服务

    关闭防火墙并且重启网络yum install samba  samba-client samba-commmon -ysystemctl start smb smbclient -L //172.25 ...

  4. Spring Cloud 没移动完 到Ribbon

    一  Spring Cloud各组件简要介绍 1. Eureka 注册中心. 帮助我们做服务的注册.服务的发现以及接口的调用 2.  Ribbo 请求负载均衡 3.  Zuul 网关.做合法性的校验. ...

  5. Nginx配置SSL报错 nginx: [emerg] unknown directive "ssl"

    Nginx配置SSL报错 nginx: [emerg] unknown directive "ssl"     出现如图所示错误,处理办法如下 去nginx解压目录下执行 ./co ...

  6. thinkphp引入模板view

    3.1 模板放在哪儿? 放在模块的view目录下并且每个控制器的模板,要在与控制器同名的目录下. 以 index.php/Home/User/add则对应的模板在 /Home/view/User/ad ...

  7. set与map

    set /*set里面没有相同的元素 所以可以用于数组去重*/ //内部去重用的是=== 对象不等 但是 NaN等 //其本身是构造函数 let s=new Set([1,2,{},{},3,4,Na ...

  8. 关于Yii2中的MVC中的视图总结(持续更新中)

    一.首先在控制器中,将处理好的数据发送给前台: $this->layout = 'base'; 这里填写视图的模板文件(可以不写这行代码,如果不写,默认为views/layouts/main.p ...

  9. Python入妖5-----正则的基本使用

    什么是正则表达式 正则表达式是对字符串操作的一种逻辑公式,就是 事先定义好的一些特定字符.及这些特定字符的组合,组成一个“规则字符”,这个“规则字符” 来表达对字符的一种过滤逻辑. 正则并不是pyth ...

  10. Error in event handler for "el.form.change": "TypeError: value.getTime is not a function"

    首先说一下我使用的实际场景 html代码: js代码: 首先说明出现原因,elementUI的日期选择器[el-date-picker]在加上格式 value-format="yyyy-MM ...