• 相机调用


    //原理:调用

    #import "ViewController.h"


    @interface ViewController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>


    @property(nonatomic,weak)UIImageView *photoImage;


    @end


    @implementation ViewController


    - (void)viewDidLoad {

        [super viewDidLoad];

        

        UIImageView *image=[[UIImageView alloc]initWithFrame:self.view.bounds];

        image.backgroundColor=[UIColor grayColor];

        [self.view addSubview:image];

        self.photoImage=image;

        

        [image setUserInteractionEnabled:YES];

        

        

    }

    //点击屏幕进行图片拍摄

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

    {

        NSLog(@"开启射像头");

        UIImagePickerController *picker=[[UIImagePickerController alloc]init];

        //设置摄像头类型 摄像头

        picker.sourceType=UIImagePickerControllerSourceTypeCamera;

        //打开相册

        //picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

        //设置代理

        picker.delegate=self;

        

        //显示控制器

        [self presentViewController:picker animated:YES completion:nil];

        

    }

    #pragma mark UIImagePickerControllerDelegate


    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

    {

        //获取图片,

        UIImage *image=info[UIImagePickerControllerOriginalImage];

        self.photoImage.image=image;

        //退出控制器

        [picker dismissViewControllerAnimated:YES completion:nil];

    }





    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

    }


    @end

  • 相关阅读:
    Jetson AGX Xavier初始化
    Jetson AGX Xavier更换apt-get源
    Mac远程访问Ubuntu
    Anaconda安装和环境的搭建
    C# NotifyIcon 托盘控件
    VS2010+OpenMP的简单使用
    VS2010+OpenCV3.4.1+zbar 64位
    datatbales 使用笔记
    ubuntu16.04 常用软件
    crontab不能正常执行的五种原因
  • 原文地址:https://www.cnblogs.com/tangranyang/p/4665316.html
Copyright © 2020-2023  润新知