zoukankan      html  css  js  c++  java
  • IOS编程之相机和相册

    概述

    IOS设备中的相机和相册,是我们在项目开发中经常会使用到的多媒体元素,使用相机可以获得最新想要的照片,而使用相册则可以访问IOS设备中的图片资源


    使用IOS设备中的相机/相册获得图片资源

    是否允许使用

    BOOL isAvailable = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera/UIImagePickerControllerSourceTypePhotoLibrary];

    跳转到相机/相册界面

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

    picker.delegate = self;

    picker.sourceType = UIImagePickerControllerSourceTypeCamera/UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:picker animated:YES completion:^{ }];


    从相机/相册中选取图片资源需要实现的代理

    代理

    UIImagePickerControllerDelegate,UINavigationControllerDelegate

    拍照或者从相册选择图片后的操作

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

      UIImage *image= [info objectForKey:@”UIImagePickerControllerOriginalImage”];

         //压缩图片

      NSData*image_data = UIImageJPEGRepresentation(image,1);

      image =[UIImage imageWithData:data];

         //输出图片文件大小

      NSLog(@“图片大小为%lu”,(unsigned long)data.length);

      //对image做一些操作

      do someoperation for image

      //操作完成,让视图消失

      [selfdismissViewControllerAnimated:YES completion:^{}];

    }

      点击取消时做的操作

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

     [self.dismissViewControllerAnimated:YES completion:^{}];

    }





  • 相关阅读:
    数据库 封装类CppSQLite3的helloword VC6
    数据库 sqlite 进阶
    数据库 sqlite3_get_table,sqlite3_free_table
    数据库 sqlite3_open,sqlite3_exec,slite3_close
    数据库 SQLite C++ 接口
    数据库 如何在VC6下使用sqlite3
    MFC CButtonST使用技巧(一)(二)(三)
    MFC CButtonST简介
    MFC CButtonST 在你的程序中如何使用CButtonST类
    MFC静态分割后锁定分隔条/限制分隔条的移动范围 方法1
  • 原文地址:https://www.cnblogs.com/IOS-Developer/p/4117231.html
Copyright © 2011-2022 走看看