zoukankan      html  css  js  c++  java
  • IOS 调用系统照相机和相册

    /**

     *  调用照相机

     */

    - (void)openCamera

    {

        UIImagePickerController *picker = [[UIImagePickerController allocinit];

        picker.delegate = self;

        picker.allowsEditing = YES//可编辑

        //判断是否可以打开照相机

        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])

        {

            //摄像头

            picker.sourceType = UIImagePickerControllerSourceTypeCamera;

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

        }

        else

        {

            NSLog(@"没有摄像头");

        }

    }

     

    /**

     *  打开相册

     */

    -(void)openPhotoLibrary

    {

        // Supported orientations has no common orientation with the application, and [PUUIAlbumListViewController shouldAutorotate] is returning YES

        

        // 进入相册

        if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])

        {

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

            imagePicker.allowsEditing = YES;

            imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

            imagePicker.delegate = self;

            [self presentViewController:imagePicker animated:YES completion:^{

                NSLog(@"打开相册");

            }];

        }

        else

        {

            NSLog(@"不能打开相册");

        }

    }

     

    #pragma mark - UIImagePickerControllerDelegate

    // 拍照完成回调

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullableNSDictionary<NSString *,id> *)editingInfo NS_DEPRECATED_IOS(2_0, 3_0)

    {

        NSLog(@"finish..");

        

        if(picker.sourceType == UIImagePickerControllerSourceTypeCamera)

        {

            //图片存入相册

            UIImageWriteToSavedPhotosAlbum(image, nilnilnil);

        }

        

        [self dismissViewControllerAnimated:YES completion:nil];

    }

    //进入拍摄页面点击取消按钮

    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

    {

        [self dismissViewControllerAnimated:YES completion:nil];

    }

  • 相关阅读:
    vue 动态生成 el-checkbox-group,动态绑定v-model的解决方法
    vue 弹窗内scrollTop取值为0的问题
    软件工程课程学习心得
    《软件工程》学习总结及获奖感言
    软件工程课程心得及小黄衫获奖感想
    Prometheus + Alertmanager 实现企业微信告警
    二进制安装Prometheus
    zabbix机器人告警配置流程
    c++不同平台崩溃解析总结
    c++跨平台开发技术总结
  • 原文地址:https://www.cnblogs.com/scode2/p/8664460.html
Copyright © 2011-2022 走看看