iOS 拍照后裁剪图片上传

iOS 拍照后裁剪图片在上传,可以直接使用系统自带的API。

//push 相机

UIImagePickerController*picker = [[UIImagePickerControlleralloc]init];

picker.delegate=self;

picker.sourceType = UIImagePickerControllerSourceTypeCamera;

picker.allowsEditing=YES;

[selfpresentViewController:pickeranimated:YEScompletion:nil];

//注意:picker.allowsEditing=YES;要设置

//代理方法获取图片

#pragma mark --选择相机的代理

#pragma mark - UIImagePickerControllerDelegate

- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker

{

[pickerdismissViewControllerAnimated:YEScompletion:nil];

}

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

{

[pickerdismissViewControllerAnimated:NOcompletion:^{

[UIApplicationsharedApplication].statusBarHidden=NO;

NSString*mediaType = [infoobjectForKey:UIImagePickerControllerMediaType];

if([mediaTypeisEqualToString:@"public.image"])

{

UIImage*originImage=[[UIImagealloc]init];

originImage=[info objectForKey:UIImagePickerControllerEditedImage];

//赋值控件

self.headImg.image= originImage;

//上传图片

[self uploadHeadImgWithImg:originImage];

}

}];

}

//注意: 只有使用originImage=[info objectForKey:UIImagePickerControllerEditedImage];才能出现裁剪图片界面。

你可能感兴趣的:(iOS 拍照后裁剪图片上传)