浅谈iPhone手机拍照功能和照片库选取功能调用

移动开发 iOS
本文介绍的是浅谈iPhone手机拍照功能和照片库选取功能调用,主要是基于代码实现,我们来看代码。

浅谈iPhone手机拍照功能和照片库选取功能调用是本文要介绍的内容,内容不多,主要是以代码实现,我们来看内容。

首先,你得实现UIImagePickerControllerDelegate,UINavigationControllerDelegate两个代理

其次定义按钮:

  1. // 从相簿里上传一张  
  2. UIButton *btn1 = [UIButton buttonWithType: UIButtonTypeRoundedRect];  
  3. btn1.frame = CGRectMake(60.0, 237.0, 200.0, 32.0);  
  4. [btn1 setTitle:@"从媒体库中选取图片" forState:UIControlStateNormal];  
  5. [btn1 addTarget:self action:@selector(picker) forControlEvents:UIControlEventTouchUpInside];  
  6. UIButton *btn2 = [UIButton buttonWithType: UIButtonTypeRoundedRect];   
  7. btn2.frame = CGRectMake(60.0, 290.0, 200.0, 32.0);  
  8. [btn2 setTitle:@"从相机获取图片" forState:UIControlStateNormal];  
  9. [btn2 addTarget:self action:@selector(picker1) forControlEvents:UIControlEventTouchUpInside]; 

实现按钮方法:

  1. // 从照片库里面选取  
  2.  
  3. -(void)picker  
  4.  
  5. {  
  6.  
  7. imagepicker = [[UIImagePickerController alloc] init];  
  8.  
  9. imagepicker.delegate = self;  
  10.  
  11. imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;  
  12. imagepicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;  
  13. imagepicker.allowsEditing = YES;  
  14. [self presentModalViewController:self.imagepicker animated:YES];  
  15. }  
  16. // 从相机获取  
  17. -(void)picker1  
  18. {  
  19. imagepicker = [[UIImagePickerController alloc] init];  
  20. imagepicker.delegate = self;  
  21. imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;  
  22. imagepicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;  
  23. imagepicker.allowsEditing = YES;  
  24. [self presentModalViewController:self.imagepicker animated:YES];  

实现代理方法:

  1. // 初始化选取  
  2. - (void)imagePickerController:(UIImagePickerController *)picker   
  3. didFinishPickingImage:(UIImage *)image   
  4. editingInfo:(NSDictionary *)editingInfo  
  5. {  
  6. myImageView.image = image;  
  7. [[picker parentViewController] dismissModalViewControllerAnimated:YES];  
  8. }  
  9. // 完成选取  
  10.  
  11. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker  
  12. {  
  13. [picker dismissModalViewControllerAnimated:YES];  

小结:浅谈iPhone手机拍照功能和照片库选取功能调用的内容介绍完了,希望本文对你有所帮助

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

2011-07-18 13:56:19

2010-07-08 14:47:37

动态路由协议

2013-02-01 10:32:06

2010-06-03 17:22:27

2018-01-05 12:02:46

iPhoneiPhone X苹果

2009-04-09 08:41:55

iphone苹果移动OS

2012-04-05 16:20:53

图片分享拍照应用

2011-01-18 09:47:33

自增ID

2012-06-04 09:49:37

个人信息安全移动智能终端

2020-10-22 06:59:09

GolangRust语言

2009-06-17 15:13:57

Java网络功能编程方法

2009-03-13 08:37:35

GoogleAndroidiPhone

2011-06-07 07:06:33

iOS 5iOSWWDC

2009-04-30 08:42:23

微软手机语音搜索移动OS

2012-02-01 09:04:08

诺基亚WPNFC

2011-03-14 14:34:57

2011-06-28 13:12:07

Qt 调用 DLL DLL

2012-04-10 08:22:14

iPhone

2011-05-18 10:10:01

iPhone 5iPhone苹果

2009-04-20 08:40:19

Iphone苹果移动OS
点赞
收藏

51CTO技术栈公众号