我目前正在使用默认的UI
ImagePickerController,并在拍摄照片后立即显示以下默认屏幕:
我的问题是,我如何能够使用自己的自定义UIViewController来查看结果图像(因此绕过此确认屏幕).
请注意,我不想使用自定义叠加层为自定义相机控件或照片库中的图像使用UIImagePicker,而只是跳过此屏幕并假设拍摄的照片是用户喜欢的.
谢谢!
解决方法
尝试使用此代码将结果图像保持为相同大小:
首先为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,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; }