zoukankan      html  css  js  c++  java
  • 系统简单的UIImagePickerController

    1.从系统相册中读取

         /*

         判断选择的读取类型是否支持

         UIImagePickerControllerSourceTypePhotoLibrary,普通相册

         UIImagePickerControllerSourceTypeCamera, 镜头(拍照、录视频)

         UIImagePickerControllerSourceTypeSavedPhotosAlbum(自己保存的图片)

         */

        if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

            self.imagePC = [[UIImagePickerController alloc] init];

            _imagePC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

            

            //相册操作由代理来监听 取消还是选择完成

            _imagePC.delegate = self;

            

            //展示相册

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

        }

    2.拍照录视频

      if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

            self.imagePC = [[UIImagePickerController alloc] init];

            _imagePC.delegate = self;

            _imagePC.sourceType = UIImagePickerControllerSourceTypeCamera;

            //图片 public.image

            //视频 public.movie

            _imagePC.mediaTypes = @[@"public.movie"];

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

        }

    3.代理

    读取图片或者视频 统一回调这个代理

    系统相册 一次只能选取一张

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{

        [self dismissViewControllerAnimated:YES completion:nil];

        

        NSLog(@"%@", info);

    //    UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

    //    NSData *data = UIImagePNGRepresentation(image);

    //    NSUInteger byte = data.length/8;

    //    NSUInteger k = byte / 1024;

    //    NSUInteger m = k / 1024;

    //    NSLog(@"%ld", m);

    }

     

    //取消按钮被按了

    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{

        [self dismissViewControllerAnimated:YES completion:nil];

    }

    4.将图片保存到系统相册

    UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

  • 相关阅读:
    XHTML学习笔记 Part3:核心属性
    XHTML学习笔记 Part2:核心元素
    XHTML学习笔记 part1
    北航非全日制-软件学院考研攻略(经验仅来自于2019年,2020年招生简章有变动,需谨慎)
    为什么能抓到网站https传输的明文密码?------顺便说说“知乎”和“支付宝”的安全性对比
    JetBrain系列学生免费授权
    印象笔记模板推荐使用
    测试用例评审总结与规范
    Django入门
    Django在根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete'
  • 原文地址:https://www.cnblogs.com/huoran1120/p/5234116.html
Copyright © 2011-2022 走看看