tto*_*tto 9 iphone autofocus avcapturesession
我正在使用基于Apple的AppCam应用程序示例的AVCaptureSession克隆Apple的相机应用程序.问题是我无法在视频预览屏幕中看到焦点矩形.我使用以下代码来设置焦点,但仍未显示焦点矩形.
  AVCaptureDevice *device = [[self videoInput] device];
if ([device isFocusModeSupported:focusMode] && [device focusMode] != focusMode) {
    NSError *error;
      printf(" setFocusMode    \n");
    if ([device lockForConfiguration:&error]) {
        [device setFocusMode:focusMode];
        [device unlockForConfiguration];
    } else {
        id delegate = [self delegate];
        if ([delegate respondsToSelector:@selector(acquiringDeviceLockFailedWithError:)]) {
            [delegate acquiringDeviceLockFailedWithError:error];
        }
    }    
}
当我使用UIImagePickerController时,默认支持自动对焦,点击焦点,并且可以看到焦点矩形.是否无法使用AVCaptureSession在视频预览图层中显示焦点矩形?
xxt*_*axx 11
焦点动画是一个完整的自定义动画,您必须自己创建.我目前遇到的问题与您完全相同:我想在点击预览图层后向用户显示一个矩形作为反馈.
您要做的第一件事是实现点按焦点,可能是您启动预览图层的位置:
UITapGestureRecognizer *tapGR = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapToFocus:)];
[tapGR setNumberOfTapsRequired:1];
[tapGR setNumberOfTouchesRequired:1];
[self.captureVideoPreviewView addGestureRecognizer:tapGR];
现在实现tap-to-focus方法本身:
-(void)tapToFocus:(UITapGestureRecognizer *)singleTap{
    CGPoint touchPoint = [singleTap locationInView:self.captureVideoPreviewView];
    CGPoint convertedPoint = [self.captureVideoPreviewLayer captureDevicePointOfInterestForPoint:touchPoint];
    AVCaptureDevice *currentDevice = currentInput.device;
    if([currentDevice isFocusPointOfInterestSupported] && [currentDevice isFocusModeSupported:AVCaptureFocusModeAutoFocus]){
        NSError *error = nil;
        [currentDevice lockForConfiguration:&error];
        if(!error){
            [currentDevice setFocusPointOfInterest:convertedPoint];
            [currentDevice setFocusMode:AVCaptureFocusModeAutoFocus];
            [currentDevice unlockForConfiguration];
        }    
    }
}
我还没有实现的最后一件事是将聚焦动画添加到预览图层或者更确切地说是保持预览图层的视图控制器.我相信可以在tapToFocus中完成:那里你已经有了接触点.只需添加动画图像视图或以触摸位置为中心的其他视图.动画完成后,删除图像视图.
| 归档时间: | 
 | 
| 查看次数: | 9764 次 | 
| 最近记录: |