zoukankan      html  css  js  c++  java
  • 拍照-相册-保存照片-上传照片=流程

    稍微整理一下

     1 //打开相机
     2 -(void)takePhoto
     3 {
     4     
     5     UIImagePickerControllerSourceType sourceType;
     6     sourceType = UIImagePickerControllerSourceTypeCamera;
     7     
     8     UIImagePickerController *ipc=[[UIImagePickerController alloc] init];
     9     ipc.sourceType=UIImagePickerControllerSourceTypeCamera;
    10     ipc.delegate=self;
    11     //是否可编辑
    12     ipc.allowsEditing=YES;
    13     
    14     [self presentViewController:ipc animated:YES completion:^{
    15         
    16     }];
    17 }
    18 
    19 
    20 //打开本地相册
    21 -(void)localPhoto
    22 {
    23     UIImagePickerController *picker = [[UIImagePickerController alloc]init];
    24     picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    25     picker.delegate = self;
    26     picker.allowsEditing = YES;
    27     [self presentViewController:picker animated:YES completion:^{
    28         
    29     }];
    30     
    31 }
    32 
    33 #pragma mark - UIImagePickerController协议方法
    34 -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    35 {
    36     
    37     UIImage *chooesImage = [info objectForKey:UIImagePickerControllerEditedImage];
    38     NSLog(@"%f,%f",chooesImage.size.width,chooesImage.size.height);
    39     
    40    //保存到相册
    41     if(picker.sourceType==UIImagePickerControllerSourceTypeCamera)
    42     {
    43         UIImageWriteToSavedPhotosAlbum(chooesImage,nil,nil,nil);
    44     }
    45     _photoView.image  =  chooesImage;
    46     NSLog(@"%f,%f",_photoView.image.size.width,_photoView.image.size.height);
    47     [self dismissViewControllerAnimated:YES completion:nil];
    48 }  
    49     
    50 //上传头像
    51 -(void)upDataUserIcon:(UIImage *)userIcon
    52 {
    53     //请求数据
    54     NSData *iconData = UIImageJPEGRepresentation(userIcon, 0.005f);
    55     NSMutableDictionary *mDict = [[NSMutableDictionary alloc]init];
    56     [mDict setValue:iconData forKey:@"avatar"];
    57 
    58     [SVProgressHUD showWithStatus:@"正在上传..."];
    59 
    60     [Networking post:[NSString stringWithFormat:@"asdf"] params: mDict success:^(id responseObject) {
    61         
    62     } failure:^(NSError *error) {
    63         NSLog(@".......");
    64     }];
    65 }
    66     
    67     
    68     
    69     
    70     
    让明天,不后悔今天的所作所为
  • 相关阅读:
    数据结构与算法基础 模块七
    操作系统
    数据结构与算法基础 模块六
    数据库技术
    数据库技术
    数据库 SQL语句
    数据结构与算法基础 模块五
    同源策略和解决
    初识单例模式
    Django—内置用户权限管理
  • 原文地址:https://www.cnblogs.com/-yun/p/5775307.html
Copyright © 2011-2022 走看看