2014-01-20 2 views
0

Я хочу создать функциональность фокуса так же, как и собственное приложение для камеры, использующее 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]; 

    } 

я пытаюсь сохранить точку фокусировки, но в следующий раз, когда я перезагрузить камеру фокус теряется.

Пожалуйста, помогите.

ответ

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

    } 


} 

Вышеупомянутый метод вызывается, когда пользователь дважды нажимает экран для фокусировки.

Смежные вопросы