稍微整理一下
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
时间: 2024-10-01 07:30:37