我想从相册中选择图片并通过相机拍摄。它编码效果很好,但我只需要选择部分图像就意味着裁剪图像设置我的imageView。
-(IBAction)chooseAlbum:(id)sender
{
imagePicker=[[UIImagePickerController alloc]init];
imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate=self;
[self presentViewController:imagePicker animated:YES completion:nil];
}
-(IBAction)takePicture:(id)sender
{
imagePicker=[[UIImagePickerController alloc]init];
imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
}
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
profileImageView.image=[info objectForKey:UIImagePickerControllerOriginalImage];
[self dismissViewControllerAnimated:YES completion:nil];
}
答案 0 :(得分:2)
开启编辑模式
imagePicker.allowsEditing = YES;
然后在您的委托方法中使用UIImagePickerControllerEditedImage
密钥
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info {
profileImageView.image=[info objectForKey:UIImagePickerControllerEditedImage];
[self dismissViewControllerAnimated:YES completion:nil];
}
答案 1 :(得分:1)
你必须添加属性imagePicker。
imagePicker.allowsEditing = YES;
答案 2 :(得分:0)
但是,如果您想要更多控制和令人愉悦的效果/动画,您还可以使用以下第三方库。
https://github.com/myang-git/iOS-Image-Crop-View