iOS开发中訪问相冊摄像像头

源代码下载地址http://download.csdn.net/download/jingjingxujiayou/7270479

在AppDelegate.m文件里

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
self.window.rootViewController = [[dateViewController alloc]init];
return YES;
}

dateViewController.h

#import <UIKit/UIKit.h>

@interface dateViewController : UIViewController<UIImagePickerControllerDelegate,UINavigationBarDelegate>
@property(nonatomic,retain)UIImageView* imageview1;
@property(nonatomic,retain)UIImagePickerController* imagepicker;
@end

dateViewController.m

//
// dateViewController.m
// datepick
//
// Created by 5_2 on 14-4-29.
// Copyright (c) 2014年 Frountion. All rights reserved.
// #import "dateViewController.h" @interface dateViewController () @end @implementation dateViewController
@synthesize imageview1,imagepicker; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
} - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view. //----------1 从网络载入图片
imageview1 = [[UIImageView alloc]initWithFrame:CGRectMake(10, 50, 300, 200)];
imageview1.backgroundColor = [UIColor yellowColor];
[self.view addSubview:imageview1];
NSURL* url = [[NSURL alloc]initWithString:@"https://www.google.com.hk/images/srpr/logo11w.png"];
NSData* data = [NSData dataWithContentsOfURL:url];
//把data转成image
UIImage* image = [UIImage imageWithData:data];
//显示图片
imageview1.image = image; //把图片转化为数据
NSData* imagedata = UIImageJPEGRepresentation(image, 1);
NSLog(@"%d",imagedata.length); //保存到相冊里面,这个能够到模拟器里的相冊产查看的。
UIImageWriteToSavedPhotosAlbum(image, self, @selector(image:didFinishSavingWithError:contextInfo:), NULL); //---------2 相冊的訪问 UIButton *buttonphoto = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttonphoto.tag = 100;
buttonphoto.frame = CGRectMake(50, 250, 80, 50);
[buttonphoto setTitle:@"訪问相冊" forState:UIControlStateNormal];
[buttonphoto addTarget:self action:@selector(look:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttonphoto]; //---------3 摄像头的訪问
UIButton *buttoncamera = [UIButton buttonWithType:UIButtonTypeRoundedRect];
buttoncamera.tag = 200;
buttoncamera.frame = CGRectMake(50, 310, 80, 50);
[buttoncamera setTitle:@"訪问摄像头" forState:UIControlStateNormal];
[buttoncamera addTarget:self action:@selector(look:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:buttoncamera]; } /*-(void)look:(UIButton*)button
{
UIImagePickerController* imagepicker = [[UIImagePickerController alloc]init];
imagepicker.delegate = self;
//訪问相冊类型的类型
//UIImagePickerControllerSourceTypePhotoLibrary,
//UIImagePickerControllerSourceTypeCamera, ===== 訪问摄像头
//UIImagePickerControllerSourceTypeSavedPhotosAlbum ======= 仅仅能訪问第一列的图片
imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//以摩擦动画的方式显示
[self presentViewController:imagepicker animated:YES completion:^{ }]; if (button.tag == 200) {
//UIImagePickerControllerCameraDeviceFront === 前摄像头
//UIImagePickerControllerCameraDeviceRear === 后摄像头
BOOL isCamrma = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
if (!isCamrma) {
NSLog(@"没有摄像头");
return;
}
//摄像头
imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//同意编辑
imagepicker.allowsEditing =YES;
}
}*/ -(void)look:(UIButton*)button
{
if (button.tag == 100) {
imagepicker = [[UIImagePickerController alloc]init];
imagepicker.delegate = self;
//訪问相冊类型的类型
//UIImagePickerControllerSourceTypePhotoLibrary,
//UIImagePickerControllerSourceTypeCamera, ===== 訪问摄像头
//UIImagePickerControllerSourceTypeSavedPhotosAlbum ======= 仅仅能訪问第一列的图片
imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
//以摩擦动画的方式显示
[self presentViewController:imagepicker animated:YES completion:^{ }]; }else { //注意摄像头的訪问须要在真机上进行 //UIImagePickerControllerCameraDeviceFront === 前摄像头
//UIImagePickerControllerCameraDeviceRear === 后摄像头
BOOL isCamrma = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
if (!isCamrma) {
NSLog(@"没有摄像头");
return;
}
//摄像头
imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
//同意编辑
imagepicker.allowsEditing =YES;
}
} //---------2 相冊的訪问
#pragma mark - UIImagePickerControllerDelegate //相冊选中之后调用
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//UIImagePickerControllerOriginalImage === 取原始图片
//UIImagePickerControllerEditedImage === 去编辑以后的图片
UIImage* image = [info objectForKey:UIImagePickerControllerEditedImage];
imageview1.image = image;
NSLog(@"info = %@",info);
[picker dismissViewControllerAnimated:YES completion:nil];
}
//取消按钮的点击事件
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:NULL];
}
//将图片保存
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
NSLog(@"error = %@",error);
} - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
} @end

iOS开发中訪问相冊摄像像头的更多相关文章

  1. iOS开发中的MVC设计模式

    我们今天谈谈cocoa程序设计中的 模型-视图-控制器(MVC)范型.我们将从两大方面来讨论MVC: 什么是MVC? M.V.C之间的交流方式是什么样子的? 理解了MVC的概念,对cocoa程序开发是 ...

  2. IOS开发中UI编写方式——code vs. xib vs.StoryBoard

    最近接触了几个刚入门的iOS学习者,他们之中存在一个普遍和困惑和疑问,就是应该如何制作UI界面.iOS应用是非常重视用户体验的,可以说绝大多数的应用成功与否与交互设计以及UI是否漂亮易用有着非常大的关 ...

  3. iOS开发中的4种数据持久化方式【二、数据库 SQLite3、Core Data 的运用】

                   在上文,我们介绍了ios开发中的其中2种数据持久化方式:属性列表.归档解档.本节将继续介绍另外2种iOS持久化数据的方法:数据库 SQLite3.Core Data 的运 ...

  4. iOS开发中你是否遇到这些经验问题

    前言 小伙伴们在开发中难免会遇到问题, 你是如何解决问题的?不妨也分享给大家!如果此文章其中的任何一条问题对大家有帮助,那么它的存在是有意义的! 反正不管怎样遇到问题就要去解决问题, 在解决问题的同时 ...

  5. iOS 开发中常见的设计模式

    最近有小伙伴问到在iOS开发中的几种设计模式,这里摘录一下别人的总结(因为已经感觉总结得差不多了,适用的可以阅读一下) 首先是开发中的23中设计模式分为三大类:1.创建型 2.结构型 3.行为型 (i ...

  6. iOS开发中遇到的一些问题及解决方案【转载】

    iOS开发中遇到的一些问题及解决方案[转载] 2015-12-29 [385][scrollView不接受点击事件,是因为事件传递失败] // //  MyScrollView.m //  Creat ...

  7. iOS开发中各种关键字的区别

    1.一些概念 1.浅Copy:指针的复制,只是多了一个指向这块内存的指针,共用一块内存. 深Copy:内存的复制,两块内存是完全不同的, 也就是两个对象指针分别指向不同的内存,互不干涉. 2.atom ...

  8. 总结iOS开发中的断点续传那些事儿

    前言 断点续传概述 断点续传就是从文件赏赐中断的地方重新开始下载或者上传数据,而不是从头文件开始.当下载大文件的时候,如果没有实现断点续传功能,那么每次出现异常或者用户主动的暂停,都会从头下载,这样很 ...

  9. iOS开发中静态库之".framework静态库"的制作及使用篇

    iOS开发中静态库之".framework静态库"的制作及使用篇 .framework静态库支持OC和swift .a静态库如何制作可参照上一篇: iOS开发中静态库之" ...

随机推荐

  1. 修改qq热键后 安全设置-》自动锁定设置 就能保存住qq的热键了

  2. spring的设计思想

    在学习Spring框架的时候, 第一件事情就是分析Spring的设计思想 在学习Spring的时候, 需要先了解耦合和解耦的概念 耦合: 简单来说, 在软件工程当中, 耦合是指对象之间的相互依赖 耦合 ...

  3. Leetcode 54:Spiral Matrix 螺旋矩阵

    54:Spiral Matrix 螺旋矩阵 Given a matrix of m x n elements (m rows, n columns), return all elements of t ...

  4. 【C语言】控制台窗口图形界面编程(七):鼠标事件

    目录 00. 目录 01. INPUT_RECORD结构 02. MOUSE_EVENT_RECORD结构 03. ReadConsoleInput函数 04. 示例程序 00. 目录 01. INP ...

  5. No-1.第一个 Python 程序

    1. 第一个 HelloWorld 程序 1.1 Python 源程序的基本概念 Python 源程序就是一个特殊格式的文本文件,可以使用任意文本编辑软件做 Python 的开发 Python 程序的 ...

  6. 洛谷——P2417 课程

    P2417 课程 裸地匈牙利算法, 贪心的不断匹配,若没匹配,则匹配:反之,判断与之匹配的点能否在找另一个点匹配,若能,抢多这个点与之匹配 时间复杂度$O(n\times m)$ #include&l ...

  7. HYSBZ - 2763 飞行路线(分层图最短路线)

    题目: Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的价 ...

  8. 4_蒙特卡罗算法求圆周率PI

    题目 蒙特卡罗算法的典型应用之一为求圆周率PI问题. 思想: 一个半径r=1的圆,其面积为:S=PI∗r2=PI/4 一个边长r=1的正方形,其面积为:S=r2=1 那么建立一个坐标系,如果均匀的向正 ...

  9. NOR flash and NAND flash

    (1)读写的基本单位 应用程序对NOR芯片操作以"字"为基本单位.为了方便对大容量NOR闪存的管理,通常将NOR闪存分成大小为128KB或者64KB的逻辑块,有时候块内还分成扇区. ...

  10. python 中文转码 Excel读csv

    大家都知道Excel读csv用的是ascii编码,我认为,ascii没有中文,所以这里指的应该是utf-8. 我遇到的问题是这样的,unity项目只能用txt文件,有一堆数据表用txt的文档保存下来了 ...