0

我想创建焦点功能,就像使用 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];

    }

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

请帮忙。

4

1 回答 1

1

我已经找到了解决方案。我在这里张贴以供将来参考。我使用的技巧是使用用户点击的新点再次设置会话。这是代码;

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

    }


}

当用户双击屏幕聚焦时调用上述方法。

于 2014-02-06T10:52:14.720 回答