我正在使用最新的SDK开发iOS应用程序。
我正在使用相机,我想进行缩放。要做到这一点,我有这个代码:
- (void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self setUpVideo];
}
- (void)setUpVideo
{
NSLog(@"Set up video");
UIView *view = [self videoPreviewView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
AVCaptureVideoPreviewLayer *newCaptureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:DataExchanger.cameraManager.captureSession];
CGRect bounds = [view bounds];
UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
CGAffineTransform t;
if (orientation == UIInterfaceOrientationLandscapeRight)
{
t = CGAffineTransformMakeRotation(-M_PI_2);
bounds = CGRectMake(bounds.origin.x, bounds.origin.y,
bounds.size.height, bounds.size.width);
}
[newCaptureVideoPreviewLayer setFrame:bounds];
[newCaptureVideoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
newCaptureVideoPreviewLayer.position = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
newCaptureVideoPreviewLayer.affineTransform = t;
[viewLayer insertSublayer:newCaptureVideoPreviewLayer below:[[viewLayer sublayers] objectAtIndex:0]];
CGAffineTransform currentTransform = CGAffineTransformIdentity;
CGAffineTransform newTransform = CGAffineTransformScale(currentTransform, 2.0f, 2.0f);
view.transform = newTransform;
}
但是我看到缩放图像与没有缩放的同一图像之间存在差异。在没有移动相机的情况下,当我进行变焦时,我看到中心向左下方移动。
也许我必须使用一个使用比例计算新中心的公式来移动videoView
个中心。
你知道如何解决这个问题吗?