gpt4 book ai didi

iPhone 相机对焦

转载 作者:搜寻专家 更新时间:2023-10-30 19:58:25 32 4
gpt4 key购买 nike

我使用以下代码对 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:] 的点与 View 的触摸点不同,而是 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];

关于iPhone 相机对焦,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8065422/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com