gpt4 book ai didi

ios - 如何将使用 UIImagePickerController 拍摄的照片设置为在自定义 UIViewController 中查看/修改?

转载 作者:可可西里 更新时间:2023-11-01 03:10:14 25 4
gpt4 key购买 nike

我目前使用的是默认的 UIImagePickerController,拍照后会立即显示以下默认屏幕:

enter image description here

我的问题是,我如何才能使用自己的自定义 UIViewController 来查看结果图像(从而绕过此确认屏幕)。
请注意,我对使用自定义相机控件或照片库中的图像的 UIImagePicker 自定义覆盖感兴趣,而只是跳过此屏幕并假设照片taken 是用户会喜欢的。

谢谢!

最佳答案

尝试使用此代码来保持生成的图像大小相同:

首先为UIImageview创建IBOutlet

-(void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
NSString *mediaType = info[UIImagePickerControllerMediaType];

[self dismissViewControllerAnimated:YES completion:nil];


if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {
OriginalImage=info[UIImagePickerControllerOriginalImage];
image = info[UIImagePickerControllerOriginalImage];
//----------
imageview.image = image; // additional method
[self resizeImage];


//---------
if (_newMedia)
UIImageWriteToSavedPhotosAlbum(image,self,@selector(image:finishedSavingWithError:contextInfo:),nil);

}
else if ([mediaType isEqualToString:(NSString *)kUTTypeMovie])
{
// Code here to support video if enabled
}

}



//---- Resize the original image ----------------------
-(void)resizeImage
{

UIImage *resizeImage = imageview.image;

float width = 320;
float height = 320;

CGSize newSize = CGSizeMake(320,320);
UIGraphicsBeginImageContextWithOptions(newSize,NO,0.0);
CGRect rect = CGRectMake(0, 0, width, height);

float widthRatio = resizeImage.size.width / width;
float heightRatio = resizeImage.size.height / height;
float divisor = widthRatio > heightRatio ? widthRatio : heightRatio;

width = resizeImage.size.width / divisor;
height = resizeImage.size.height / divisor;

rect.size.width = width;
rect.size.height = height;

//indent in case of width or height difference
float offset = (width - height) / 2;
if (offset > 0) {
rect.origin.y = offset;
}
else {
rect.origin.x = -offset;
}

[resizeImage drawInRect: rect];

UIImage *smallImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

imageview.image = smallImage;
imageview.contentMode = UIViewContentModeScaleAspectFit;
}

关于ios - 如何将使用 UIImagePickerController 拍摄的照片设置为在自定义 UIViewController 中查看/修改?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20713357/

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