本文介绍了iPhone相机聚焦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码聚焦iphone相机。但它没有用。我从Apple的AVCam示例代码中获取此代码。我做错了吗?有没有任何方法可以检测
是否确实关注了iPhone?
I used the below code for focusing the iphone camera. But it is not working. I take this code from the AVCam sample code of Apple. Am I doing anything wrong? Is there any method todetect if the iPhone did focussing?
-(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(见文档)。
所以你必须这样做:
The point for [AVCaptureDevice setFocusPointOfInterest:]
is not the same as the touch point of the view, but a point between 0,0 and 1,1 (see docs).So you have to do:
CGPoint point = [touch locationInView:self.cameraView];
point.x /= self.cameraView.frame.size.width;
point.y /= self.cameraView.frame.size.height;
[self focusAtPoint:point];
这篇关于iPhone相机聚焦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!