【发布时间】:2014-02-11 11:15:25
【问题描述】:
我正在使用 UIImagePickerController 和自定义 Overlay 构建应用程序。所做的是比较两个图像(前图像和后图像)。拍摄后照片时,我使用自定义叠加层与前图像(请参阅所附图像)。
iPhone 5 - ios7
iPhone 4 - iOS7(拍照时)
iPhone 4 - iOS 7(拍照后)
查看 iPhone 4 和 iPhone 5 相机视图的大小差异。
应用程序适用于 iPhone 5 屏幕尺寸(ios 6 和 ios7)。但是 iPhone 4/4s 的屏幕尺寸,它只适用于 iOS6。问题在于 iphone 4/4s(仅限 ios7),相机视图采用全屏显示。 这意味着,你可以注意到 iPhone 5 相机视图大小 ~ 320*427 (iOS 6 和 iOS 7) iPhone 4 相机视图尺寸 ~ 320*427 (iOS 6) 但 iPhone 4 相机视图大小 ~ 320*480 (iOS 7)。
图片拍摄后,拟合为320*427的实际尺寸。由于这个问题,我无法在 iPhone 4 iOS7 上将图像与相机视图对齐(因为它的尖叫声为 320*480)。
有没有人遇到过这个奇怪的问题。我几乎尝试了一切,但没有运气。有什么想法吗???
这是我在照片叠加之前使用自定义加载相机视图的代码。
- (void)loadCameraWithImage
{
if (!isLoadedOnce)
{
isLoadedOnce = YES;
UIImagePickerController *cameraView = [[UIImagePickerController alloc] init];
cameraView.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraView.wantsFullScreenLayout = NO;
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
[self setEdgesForExtendedLayout:UIRectEdgeNone];
}
// crop before image
UIImage *imgTmpCropped = [self imageByCropping:imgBefore toRect:CGRectMake(0, 0, imgBefore.size.width/2, imgBefore.size.height)];
UIImage *overleyImage = [[UIImage alloc] initWithCGImage: imgTmpCropped.CGImage
scale: [UIScreen mainScreen].scale
orientation: UIImageOrientationDownMirrored];
UIImageView *crosshairView;
UIImageView *beforeView;
CGFloat screenHieght = [UIScreen mainScreen].bounds.size.height;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
//overleyImage = [UIImage imageNamed:@"overlay_ipad.png"];
crosshairView = [[UIImageView alloc] initWithImage:overleyImage];
crosshairView.frame = CGRectMake(0, 0, 768, 1024);
[crosshairView setUserInteractionEnabled:YES];
crosshairView.backgroundColor = [UIColor clearColor];
beforeView = [[UIImageView alloc] initWithImage:overleyImage];
beforeView.frame = CGRectMake(0, 0, 384, 1024);
beforeView.alpha = 0.5;
beforeView.contentMode = UIViewContentModeScaleAspectFill;
}
else {
//overleyImage = [UIImage imageNamed:@"overleyImageAfter.png"];
crosshairView = [[UIImageView alloc] init];
beforeView = [[UIImageView alloc] initWithImage:overleyImage];
if(screenHieght>500){
crosshairView.frame = CGRectMake(0, 60, 320, 480);
beforeView.frame = CGRectMake(0, 70, 160, 427);
}
else{
if([[[UIDevice currentDevice] systemVersion] floatValue] <7.0){
crosshairView.frame = CGRectMake(0, 0, 320, 480);
beforeView.frame = CGRectMake(0, 0, 160, 427);
}
else{
crosshairView.frame = CGRectMake(0, 0, 320, 480);
beforeView.frame = CGRectMake(0, 0, 160, 480);
}
}
[crosshairView setUserInteractionEnabled:YES];
crosshairView.backgroundColor = [UIColor clearColor];
beforeView.alpha = 0.5;
beforeView.contentMode = UIViewContentModeScaleToFill;
}
//[crosshairView addSubview:beforeView];
//set our custom overlay view
cameraView.cameraOverlayView = beforeView;
cameraView.delegate = (id)self;
cameraView.showsCameraControls = YES;
cameraView.navigationBarHidden = YES;
cameraView.toolbarHidden = YES;
[cameraView setHidesBottomBarWhenPushed:YES];
[self.view.window.rootViewController presentViewController:cameraView animated:YES completion:nil];
isLoadedOnce = NO;
}
}
【问题讨论】:
-
你有没有找到解决办法?我面临着类似的问题。
-
我可以解释这个问题。但是你找到解决办法了吗?使用 iPhone 4 (iOS 7):图像大小:{1936, 2592} 这是您使用“UIImagePickerControllerOriginalImage”从信息字典中选择 uiimage,但视图/窗口大小为:{320, 416} 比例:2。问题是宽度是 6.05 倍和身高差不多是6.23。因此,当您看到此图像时,它会失真。如果你发现了一些东西,你可以分享一下吗?干杯
-
遗憾的是没有解决方案。在我的项目中,我不得不克服这个限制
-
也许通过 AVFoundation 编写您自己的自定义图像选择器将是解决方案?我有在 UIImagePickerController 中进行自定义的经验,这很痛苦。当我创建自己的选择器时,我就可以做所有正确的事情了:)
-
您好,您是否尝试过使用 AVCapture。希望它能解决你的问题。
标签: ios iphone objective-c ios7 uiimagepickercontroller