簡體   English   中英

使用AVCam像本機相機應用程序一樣對焦

[英]Focus using AVCam like native camera app

我想像使用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];

    }


}

當用戶雙擊屏幕以進行聚焦時,將調用上述方法。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM