博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS 开发调用相机以及获取相册照片功能
阅读量:4085 次
发布时间:2019-05-25

本文共 2568 字,大约阅读时间需要 8 分钟。

  http://www.cnblogs.com/fantasy940155655/p/5799132.html

//添加代理方法

@interface MineViewController () <UITableViewDelegate, UITableViewDataSource, PayCellDelegate, UINavigationControllerDelegate, UIImagePickerControllerDelegate, UIActionSheetDelegate>

 

 

//定义消息框

    UIActionSheet * act =[[UIActionSheet alloc]initWithTitle:@"请选择图片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"选择相册",@"选择相机", nil];

    //显示消息框

    [act showInView:self.view];

 

//消息框代理实现

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{

    //定义图片选择器

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

    //判断

    switch (buttonIndex) {

        case 0:

            //判断系统是否允许选择 相册

            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

                //图片选择是相册(图片来源自相册)

                picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

                //设置代理

                picker.delegate=self;

                //模态显示界面

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

                

            }

            break;

        case 1://判断系统是否允许选择 相机

            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

                //图片选择是相册(图片来源自相册)

                picker.sourceType = UIImagePickerControllerSourceTypeCamera;

                //设置代理

                picker.delegate=self;

                //模态显示界面

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

            }

            else {

                NSLog(@"不支持相机");

            }

            

            

            break;

            

            

        default:

            break;

    }

}

 

 

//实现图片选择器代理

//参数:图片选择器  字典参数

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

    //通过key值获取到图片

    UIImage * image =info[UIImagePickerControllerOriginalImage];

    NSLog(@"image=%@  info=%@",image, info);

    

    //判断数据源类型

    if (picker.sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {

        

        //设置图片背景

        [userIconBtn setBackgroundImage:image forState:UIControlStateNormal];

        NSUserDefaults * user = [NSUserDefaults standardUserDefaults];

        NSData* imgData = UIImageJPEGRepresentation(image, 1);

        isPhotoChoose = YES;

        NSLog(@"第一次调用这个方法");

        [user setObject:imgData forKey:@"saveIcon"];

        [user synchronize];

 

        [self dismissViewControllerAnimated:YES completion:nil];

    }

    if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {

        NSLog(@"在相机中选择图片");

        UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);

        

        //设置图片背景

        [userIconBtn setBackgroundImage:image forState:UIControlStateNormal];

        NSUserDefaults * user = [NSUserDefaults standardUserDefaults];

        NSData* imgData = UIImageJPEGRepresentation(image, 1);

        isPhotoChoose = YES;

        NSLog(@"第一次调用这个方法");

        [user setObject:imgData forKey:@"saveIcon"];

        [user synchronize];

        

        [self dismissViewControllerAnimated:YES completion:nil];

    }

}

你可能感兴趣的文章
ACfly之所以不怕炸机因为它觉得某个传感器数据不安全就立马不用了
查看>>
我发觉,不管是弄ROS OPENCV T265二次开发 SDK开发 caffe PX4 都是用的C++
查看>>
ROS的安装(包含文字和视频教程,我的ROS安装教程以这篇为准)
查看>>
国内有个码云,gitee
查看>>
原来我之前一直用的APM固件....现在很多东西明白了。
查看>>
realsense-ros里里程计相关代码
查看>>
似乎写个ROS功能包并不难,你会订阅话题发布话题,加点逻辑处理,就可以写一些基础的ROS功能包了。
查看>>
if __name__ == ‘__main__‘:就是Python里的main函数,脚本从这里开始执行,如果没有main函数则从上到下顺序执行。
查看>>
PX4官方用户和开发手册的首页面是会给你选择英文和中文的
查看>>
网络协议栈我是不是可以这么理解,就是把你要发送的数据自动处理成TCPIP格式的消息发出去,这种底层的转换不需要你弄了。
查看>>
除了LwIP还有uIP
查看>>
《跟工程师学嵌入式开发》这本书最后的终极项目我反而觉得有说头
查看>>
博士的申请考核制
查看>>
那些硬件的初始化函数主要是在做些上什么?
查看>>
MAVLink学习之路05_MAVLink应用编程接口分析(也有讲STM32下的收发函数)
查看>>
找到了中文版的mavlink手册
查看>>
浅谈飞控开发的仿真功能
查看>>
我觉得在室内弄无人机开发装个防撞机架还是很有必要的,TBUS就做得很好。
查看>>
serial也是见到很多次了,似乎它就是一种串行通信协议
查看>>
TBUS的一些信息
查看>>