iPhone 相机对焦

发布于 2024-12-15 02:38:28 字数 860 浏览 0 评论 0原文

我使用下面的代码来对焦 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

简单气质女生网名 2024-12-22 02:38:28

[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];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文