#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. 设置input的样式

    css中的 ” 七层重叠法 ” :即网页内容先后顺序分别为:背景边框,负值z-index,display:block,浮动,display:inline-block,z-index:auto,正值z- ...

  2. 移动性能测试 | 持续集成中的 Android 稳定性测试

    前言 谈到Android稳定测试,大多数会联想到使用monkey工具来做测试.google官方提供了monkey工具,可以很快速点击被应用,之前我有一篇帖子提到了monkey工具的使用,详见: htt ...

  3. SpringBoot中通过实现WebMvcConfigurer完成参数校验

    在Spring5.0和SpringBoot2.0中废弃了WebMvcConfigurerAdapter类. 现有两种解决方案 1 直接实现WebMvcConfigurer (官方推荐)2 直接继承We ...

  4. 谨慎使用多线程中的fork 学习!!!!

    前言 在单核时代,大家所编写的程序都是单进程/单线程程序.随着计算机硬件技术的发展,进入了多核时代后,为了降低响应时间,重复充分利用多核cpu的资源,使用多进程编程的手段逐渐被人们接受和掌握.然而因为 ...

  5. tomcat异常[0]--java.lang.ClassNotFoundException: org.apache.taglibs.standard.tlv.JstlCoreTLV

    自己建了一个项目,启动项目的时候,发生了java.lang.ClassNotFoundException: org.apache.taglibs.standard.tlv.JstlCoreTLV异常. ...

  6. C# IO流 File.Exists,Directory.Exists, File.Create,Directory.CreateDirectory

    void Start() { CreateDirectory(); CreateFile(); } //平台的路径(封装起来的一个属性,这不是一个方法) public string path { ge ...

  7. LeetCode 441.排列硬币(C++)

    你总共有 n 枚硬币,你需要将它们摆成一个阶梯形状,第 k 行就必须正好有 k 枚硬币. 给定一个数字 n,找出可形成完整阶梯行的总行数. n 是一个非负整数,并且在32位有符号整型的范围内. 示例 ...

  8. 《深入浅出Node.js》学习笔记(一)

    看了朴灵前辈的node.js系列文章,很开阔视野,虽然能力有限还是有很多不懂,但是还是希望能写下笔记,初步对node.js有点了解. 一.概念 Node.js不是JS应用.而是JS运行平台 Node. ...

  9. pat1002. A+B for Polynomials (25)

    1002. A+B for Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue T ...

  10. EF框架

    Linq to EF 添加: //用户注册int IUserDAO.Register(Users user) { ; using (EF.ddgwDBEntities context = new EF ...