使用AVCAM之类的焦点,例如本机相机应用



我想像使用AVCAM的本机相机应用一样创建焦点功能,但无法创建相同的功能。我正在使用上述代码:

if ([[[captureManager videoInput] device] isFocusPointOfInterestSupported]) {
        CGPoint tapPoint = [tgr locationInView:[self videoPreviewView]];
        CGPoint convertedFocusPoint = [self convertToPointOfInterestFromViewCoordinates:tapPoint];
        [self addLayoutsOfAutoFocus:tapPoint];
        [USERDEFAULTS setValue:[NSString stringWithFormat:@"%f",convertedFocusPoint.x] forKey:x_value];
        [USERDEFAULTS setValue:[NSString stringWithFormat:@"%f",convertedFocusPoint.y] forKey:y_value];
        [USERDEFAULTS synchronize];
        [captureManager continuousFocusAtPoint:convertedFocusPoint];
        [captureManager continuousExpousureAtPoint:convertedFocusPoint];
    }

我试图保存重点点,但是下次我重新加载相机时,焦点就会丢失。

请帮助。

我找到了解决方案。我在此处发布以备将来参考。我使用的技巧是用用户点击的新点再次设置会话。这是代码;

- (void)tapToContinouslyAutoFocus:(UIGestureRecognizer *)tgr
{
if ([[[captureManager videoInput] device] isFocusPointOfInterestSupported]) {
        CGPoint tapPoint = [tgr locationInView:[self videoPreviewView]];
        CGPoint convertedFocus = [self convertToPointOfInterestFromViewCoordinates:tapPoint];
        CGPoint convertedFocusPoint=CGPointMake(convertedFocus.y, convertedFocus.x);
        [self addLayoutsOfAutoFocus:tapPoint];
        [USERDEFAULTS setValue:[NSString stringWithFormat:@"%f",convertedFocusPoint.x] forKey:x_value];
        [USERDEFAULTS setValue:[NSString stringWithFormat:@"%f",convertedFocusPoint.y] forKey:y_value];
        [USERDEFAULTS synchronize];
        [[self captureManager] setSession:nil];
        [[self captureManager] setupSession];
        [captureManager autoFocusAtPoint:convertedFocusPoint];
        [captureManager autoExposureAtPoint:convertedFocusPoint];
    }

}

当用户双击屏幕焦点时,上述方法是调用的。

最新更新