zoukankan      html  css  js  c++  java
  • ios中调用摄像头

    @interface ViewController ()
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        UIButton *button=[UIButton buttonWithType:UIButtonTypeRoundedRect];
        button.frame=CGRectMake(0, 0, 200, 50);
        [button setTitle:@"aa" forState:UIControlStateNormal];
        [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [self.view addSubview:button];
    }
    
    -(void)click:(UIButton *)btn{
        
        UIImagePickerController *imagePicker=[[UIImagePickerController alloc] init];
        imagePicker.delegate=self;
    //    imagePicker.view.frame=s
        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
         imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
            
        }
       // imagePicker.allowsEditing=YES;
    //    [self.view addSubview:imagePicker.view];
    [self presentViewController:imagePicker animated:YES completion:^{
        
    }];
    }
    
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
        
    }
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
        [self dismissViewControllerAnimated:YES completion:nil];
        NSLog(@"%@",info);
      UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
    
        self.image.image=image;
    }
    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
        [self dismissViewControllerAnimated:YES completion:^{
            
        }];
    }

    参照文章http://my.oschina.net/CarlHuang/blog/139997

    http://my.oschina.net/chen106106/blog/48853

  • 相关阅读:
    Git Stash用法
    动态设置ImageView的宽高以及位置
    【算法笔记】B1047 编程团体赛
    【算法笔记】B1043 输出PATest
    【算法笔记】B1042 字符统计
    【算法笔记】B1039 到底买不买
    【算法笔记】B1038 统计同成绩学生
    【算法笔记】B1033 旧键盘打字
    【算法笔记】B1029 旧键盘
    【算法笔记】B1048 数字加密
  • 原文地址:https://www.cnblogs.com/gcb999/p/3223469.html
Copyright © 2011-2022 走看看