zoukankan      html  css  js  c++  java
  • iOS 6编程使用Photo Library(照片库)和相机

    将照片库和App集成,可直接访问存储在iPhone、iPad 中的任何图像或拍摄新照片,并在App 中使用。

    1. 为了使用 UIImagePickerController,需要将类声明为遵守2个协议:UIImagePickerControllerDelegate和UINavigationControllerDelegate。

    @interface NoteViewController : UIViewController<UIImagePickerControllerDelegate, UINavigationControllerDelegate>

    2. 显示图像选择器

    下面是点击设置按钮后,需要调用的方法 – 显示图像选择器,让用户选择图像。
    - (IBAction)settingButton:(id)sender {
    UIImagePickerController *imagePicker;
    imagePicker = [[UIImagePickerController alloc] init];

    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

    imagePicker.delegate = self;
    [self presentViewController:imagePicker animated:YES completion:nil];
    // [self presentModalViewController:imagePicker animated:YES];
    }

    上述注释的代码,在iOS 6  中不赞成使用。

    3. 显示选定的图像

    在用户选择好图像之后,为了对用户选择的图像做出响应,还需要实现委托方法imagePickerController:didFinishPickingMediaWithInfo:,下面是具体的代码:

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    [self dismissViewControllerAnimated:YES completion:nil];
    //[self dismissModalViewControllerAnimated:YES];
    self.backgroundImageView.image = [info objectForKey:UIImagePickerControllerOriginalImage];
    }

    实现在当前场景的UIImageView元素中显示用户选择的图像。上述注释的代码,在iOS 6  中不赞成使用。





  • 相关阅读:
    视频测试序列的下载地址【转】
    RDO、SAD、SATD、λ相关概念【转】
    RGB、YUV和YCbCr介绍【转】
    H.264和HEVC分析软件和工具【转】
    Mysql——Innodb和Myisam概念与数据恢复
    ubuntu个人初始配置记录
    H.264学习笔记6——指数哥伦布编码
    H.264学习笔记5——熵编码之CAVLC
    C/C++语言学习——内存分配管理
    H.264学习笔记4——变换量化
  • 原文地址:https://www.cnblogs.com/tuncaysanli/p/2727946.html
Copyright © 2011-2022 走看看