iPhone 相机对焦
我使用下面的代码来对焦 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");
}
}
}
}
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 to
detect 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");
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
[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: