zoukankan      html  css  js  c++  java
  • 访问相册, 从相册中选取图片

    @interface OneViewController ()<UIImagePickerControllerDelegate, UINavigationControllerDelegate>{

        UIImageView *imageView;

    }

    @end

    @implementation OneViewController

    - (void)viewDidLoad {

        [super viewDidLoad];

        self.view.backgroundColor = [UIColor yellowColor];

        

        

        //UIImageView 继承于UIView

        imageView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 100, 150)];

        imageView.backgroundColor = [UIColor grayColor];

        [self.view addSubview:imageView];

        

        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];

        button.frame = CGRectMake(100, 200, 100, 100);

        button.layer.cornerRadius = 50;

        [button addTarget:self action:@selector(camera) forControlEvents:(UIControlEventTouchUpInside)];

        [button setTitle:@"相机" forState:(UIControlStateNormal)];

        [self.view addSubview:button];

        button.backgroundColor = [UIColor redColor];

        

        UIButton *mButton = [UIButton buttonWithType:(UIButtonTypeCustom)];

        mButton.frame = CGRectMake(50, 400, 100, 50);

        [mButton addTarget:self action:@selector(photo) forControlEvents:(UIControlEventTouchUpInside)];

        mButton.backgroundColor = [UIColor redColor];

        [mButton setTitle:@"相册" forState:(UIControlStateNormal)];

        [self.view addSubview:mButton];

    }

    - (void)camera {

        //判断是否由摄像头

        BOOL isCamera = [UIImagePickerController isCameraDeviceAvailable:(UIImagePickerControllerCameraDeviceRear)];

    //UIImagePickerControllerCameraDeviceRear后置摄像头

     //前置摄像头UIImagePickerControllerCameraDeviceFront

        if (!isCamera) {

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

            return;

        }

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

        imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        imagePicker.delegate = self;

        imagePicker.editing = YES;//相机照的照片是否允许编辑

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

        }];

        

    }

    //调取相册

    - (void)photo {

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

        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

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

            NSLog(@"打开系统相册");

        }];

        imagePicker.delegate = self;

        [imagePicker release];

    }

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {

        //选取相册照片

        imageView.image = image;

        [self dismissViewControllerAnimated:YES completion:^{

        }];

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    @end

  • 相关阅读:
    Scala In 5 Years – My Prediction « GridGain – Real Time Big Data
    牛魔王珍满福拉面 北京团购网|京东团购
    Build WebKit On Windows 白果果白的专栏 博客频道 CSDN.NET
    fabulous
    Selenimu做爬虫 oscarxie 博客园
    EA gpl
    数据挖掘与Taco Bell编程
    test cpp could not compiled on ubuntu use g++,i'll tried lateor on win platform
    How to use ActiveRecord without Rails
    svn添加新项目管理并添加到trac 知识是一种越吃越饿的粮食 ITeye技术网站
  • 原文地址:https://www.cnblogs.com/hsxblog/p/4948361.html
Copyright © 2011-2022 走看看