標籤:
稍微整理一下
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)localPhoto22 {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 *)info35 {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 *)userIcon52 {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
拍照-相簿-儲存照片-上傳照片=流程