#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. Linux忘记roo密码的解决办法

    Linux忘记root密码有三种解决办法: 下面详细介绍第一种: 重启系统后出现GRUB界面在引导装载程序菜单上,用上下方向键选择你忘记密码的那个系统键入“e” 来进入编辑模式.   接下来你可以看到 ...

  2. Java升级替换java version "1.5.0"

    首先进行java安装 http://www.cnblogs.com/someone9/p/8670585.html 2. 然后查看版本信息,仍然是1.5.0 [root@OKC java]# java ...

  3. my21_myloader -o参数

    -o 参数 如果不使用-o参数,遇到第一个有主键或者唯一约束的数据,则退出当前线程:如果有-o参数,则删除原来的表,创建新表,再插入数据,主键不会发生变化. ** Message: Dropping ...

  4. 查看Oracle当前连接数

    SQL> select count(*) from v$session #当前的连接数 SQL> Select count(*) from v$session where status=' ...

  5. 使用PIE对IE6、7、8进行CSS3兼容介绍和经验总结

    下面说说如何对 IE10 以下版本的浏览器进行部分 CSS3 兼容 国外团队开发的兼容插件,去年做项目时才发现,非常强大 主角:PIE.js ,  PIE.htc    两种方法可以实现 官方网站:h ...

  6. C#取得程序的根目录以及判断文件是否存在

    一:获取根目录的方法 取得控制台应用程序的根目录方法方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径方法2.AppDomain.CurrentDo ...

  7. Ubuntu上的相关问题

    一.解决Ubuntu中vi命令的编辑模式下不能正常使用方向键和退格键的问题 在Ubuntu中,进入vi命令的编辑模式,发现按方向键不能移动光标,而是会输出ABCD,以及退格键也不能正常删除字符.这是由 ...

  8. ajax多次请求的一个效果思路

    首先页面加载时候显示遮罩层 jQuery(function() { show_dialog(); //tianxie(); }); 定义一个全局数组,用于存放问题id var qar = []; 循环 ...

  9. hystrix应用介绍(四)

    前几章已经讲了hystrix的应用场景,以及如何使用,本章我们针对如何进行hystrix参数配置做一些分析 //异步的执行 @HystrixCommand(groupKey = "testK ...

  10. JSP中的<%%>,<%! %>,<%= %>,<%-- --%>

    <%  %>             添加java代码 <%!   %>   添加java方法 <%= %>    将变量或表达式输出到页面 <%--   - ...