我使用下面的代码来对焦 iPhone 相机。但它不起作用。我从Apple的AVCam示例代码中获取了这段代码。我做错了什么吗?有什么方法可以
检测iPhone是否对焦?
-(void) focusAtPoint:(CGPoint)point
{
AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];;
if (device != nil) {
if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
NSError *error;
if ([device lockForConfiguration:&error]) {
[device setFocusPointOfInterest:point];
[device setFocusMode:AVCaptureFocusModeAutoFocus];
[device unlockForConfiguration];
} else {
NSLog(@"Error in Focus Mode");
}
}
}
}
要点为[AVCaptureDevice setFocusPointOfInterest:]
与视图的触摸点不同,而是 0,0 和 1,1 之间的点(请参阅文档)。
所以你必须这样做:
CGPoint point = [touch locationInView:self.cameraView];
point.x /= self.cameraView.frame.size.width;
point.y /= self.cameraView.frame.size.height;
[self focusAtPoint:point];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)