码迷,mamicode.com
首页 > Web开发 > 详细

拍照-相册-保存照片-上传照片=流程

时间:2016-08-16 10:38:35      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:

 

稍微整理一下

 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     

 

拍照-相册-保存照片-上传照片=流程

标签:

原文地址:http://www.cnblogs.com/-yun/p/5775307.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!