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  中不赞成使用。





  • 相关阅读:
    深度学习中常见问题
    freespace
    跑superpixel的程序
    python处理图片的一些操作
    跑edgebox
    tensorflow安装
    matlab启动
    stixel 理解
    stixel-world跑在kitti数据集
    小议中国人的乡土情结
  • 原文地址:https://www.cnblogs.com/tuncaysanli/p/2727946.html
Copyright © 2011-2022 走看看