iPhone应用开发之调用系统照相机

移动开发 iOS
本文介绍的是IPhone应用开发之UIImagePickerController调用系统照相机,很详细的介绍了iphone应用程序的一个实例,来看内容。

IPhone应用开发之UIImagePickerController调用系统照相机是本文要介绍的内容,不多说,我们来看内容。iphone api中提供了调用系统照相机的接口,我们只需调用相应的界面,即刻在自己的程序中获取相机图片.下面是一个非常简单的调用系统照相机的例子.

相应的界面如下:

iPhone应用开发之UIImagePickerController调用系统照相机 

iPhone应用开发之UIImagePickerController调用系统照相机 iPhone应用开发之UIImagePickerController调用系统照相机

***可以编辑图片和使用相应的图片.

下面是主要代码:

  1. - (void) addPicEvent   
  2. {   
  3.     //先设定sourceType为相机,然后判断相机是否可用(ipod)没相机,不可用将sourceType设定为相片库   
  4.     UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;   
  5.     if (![UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {   
  6.         sourceType = UIImagePickerControllerSourceTypePhotoLibrary;   
  7.     }     
  8.     UIImagePickerController *picker = [[UIImagePickerController alloc] init];   
  9.     picker.delegate = self;   
  10.     picker.allowsEditing = YES;   
  11.     picker.sourceType = sourceType;   
  12.     [self presentModalViewController:picker animated:YES];   
  13.     [picker release];   
  14. }   
  15. - (void)saveImage:(UIImage *)image {   
  16.     NSLog(@"保存");   
  17. }   
  18. #pragma mark –   
  19. #pragma mark Camera View Delegate Methods   
  20. - (void)imagePickerController:(UIImagePickerController *)picker   
  21. didFinishPickingMediaWithInfo:(NSDictionary *)info {   
  22.     [picker dismissModalViewControllerAnimated:YES];   
  23.     UIImage *image = [[info objectForKey:UIImagePickerControllerEditedImage] retain];   
  24.     [self performSelector:@selector(saveImage:)   
  25.                withObject:image   
  26.                afterDelay:0.5];   
  27. }   
  28. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {   
  29.     [picker dismissModalViewControllerAnimated:YES];   

源代码:http://easymorse-iphone.googlecode.com/svn/trunk/CameIphone/

小结:IPhone应用开发之UIImagePickerController调用系统照相机的内容介绍完了,希望本文对你有所帮助!

责任编辑:zhaolei 来源: 互联网
相关推荐

2022-12-15 17:35:37

2015-11-17 11:02:35

2021-11-02 22:50:10

鼠标计算机传感器

2017-05-23 10:17:40

互联网

2011-08-10 10:10:21

iPhoneUIPopoverCo

2011-08-11 10:03:43

iPhonecocoaNSRunLoop

2011-08-11 17:15:54

iPhone归档

2011-08-09 11:36:41

iPhoneUIPickerVieDEMO

2011-08-17 15:19:38

iPhone应用数据

2011-08-03 16:01:24

iPhone应用开发 自动登陆

2012-10-29 10:59:27

Windows 8

2013-11-18 10:27:05

Tizen智能家居

2012-03-02 10:35:22

金山快盘云相机

2011-08-08 10:10:14

iPhone开发 图片 方法

2011-08-09 17:29:29

iPhone文件屏幕

2011-08-08 16:56:44

iPhone 字符处理 视图

2011-08-01 18:27:58

iPhone开发 UISearchBa

2011-07-19 09:58:36

2011-07-19 09:46:38

2011-07-08 14:58:16

iPhone Xcode iOS
点赞
收藏

51CTO技术栈公众号