gpt4 book ai didi

ios - 如何在显示时裁剪 UIImagePickerController 拍摄的照片

转载 作者:可可西里 更新时间:2023-11-01 03:05:16 27 4
gpt4 key购买 nike

当我使用 UIImagePickerController 拍照时,图片比屏幕上可见的要多...我怎样才能拍照/裁剪它,使其与我在屏幕上看到的完全一样?

编辑:我将添加代码来说明我的问题:

- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
imagePickerController.sourceType = sourceType;
imagePickerController.delegate = self;
imagePickerController.showsCameraControls = NO;
imagePickerController.allowsEditing = YES;

if (sourceType == UIImagePickerControllerSourceTypeCamera)
{
[[NSBundle mainBundle] loadNibNamed:@"OverlayView" owner:self options:nil];
self.overlayView.frame = imagePickerController.cameraOverlayView.frame;
imagePickerController.cameraOverlayView = self.overlayView;
//self.overlayView = nil;
self.overlayImage.image = self.imageView.image;
self.overlayImage.alpha = 0.5;

UISlider *slider=[[UISlider alloc]initWithFrame:CGRectMake(60, 80, 200, 30)];
[slider setMaximumValue:1.0];
[slider setMinimumValue:0.0];
[slider setValue:0.5];
[slider addTarget:self action:@selector(sliderChanged:) forControlEvents:UIControlEventValueChanged];

if (self.working == TRUE)
{
[imagePickerController.cameraOverlayView addSubview:self.overlayImage];
[imagePickerController.cameraOverlayView addSubview:slider];
}
}

self.imagePickerController = imagePickerController;
[self presentViewController:self.imagePickerController animated:YES completion:nil];
}

didFinishPickingMediaWithInfo:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self dismissViewControllerAnimated:YES completion:NULL];

//this works, image is displayed
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
//this doesn't work, image is nil
UIImage *image = [info objecyForKey:UIImagePickerControllerEditedImage];

[self.imageView setImage:image];
self.working = TRUE;

self.imagePickerController = nil;
//[self dismissViewControllerAnimated:YES completion:NULL];
}

imagePickerController.showsCameraControls = NO; 时,我可以使用 UIImagePickerControllerEditedImage 吗?

最佳答案

您可以根据信息字典的键获取原始图像或裁剪图像。

pickedImageEdited 将是您要查找的裁剪图像,而 pickedImageOriginal 将是完整的原始图像。

-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *pickedImageOriginal = [info objectForKey:UIImagePickerControllerOriginalImage];

UIImage *pickedImageEdited = [info objectForKey:UIImagePickerControllerEditedImage];

//do your stuff

[self dismissViewControllerAnimated:YES completion:nil];
}

关于ios - 如何在显示时裁剪 UIImagePickerController 拍摄的照片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18932098/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com