繁体   English   中英

模拟相机应用程序“点按焦点”

[英]Emulating the camera apps 'tap to focus'

我正在努力模仿内置相机应用程序的基本功能。 到目前为止,我已经陷入了“重点关注”功能。

我有一个UIView,当我在UIView上点击一根手指时,我正在收集UITouch事件。 调用以下方法但相机焦距和曝光不变。

-(void)handleFocus:(UITouch*)touch
{ 
     if( [camera lockForConfiguration:nil] )
     {     
          CGPoint location = [touch locationInView:cameraView];

          if( [camera isFocusPointOfInterestSupported] )
               camera.focusPointOfInterest = location;

          if( [camera isExposurePointOfInterestSupported] )
               camera.exposurePointOfInterest = location;


          [camera unlockForConfiguration];
          [cameraView animFocus:location];
     }
}

'camera'是我的AVCaptureDevice并且它是非零的。 也许有人可能会告诉我哪里出错了?

线索和嘘声都欢迎。

M.

这个片段可能对你有所帮助......有一个苹果浮动提供的CamDemo让你可以聚焦,点击时更改曝光,设置闪光灯,交换相机等等,它可以很好地模拟相机应用程序,不确定你是否能够找到它,因为它是wwdc的一部分,但如果你在评论中留下一些电子邮件地址,我可以通过电子邮件发送给你样例代码......

- (void) focusAtPoint:(CGPoint)point

{

    AVCaptureDevice *device = [[self videoInput] device];

    if ([device isFocusPointOfInterestSupported] && [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {

        NSError *error;

        if ([device lockForConfiguration:&error]) {

            [device setFocusPointOfInterest:point];

            [device setFocusMode:AVCaptureFocusModeAutoFocus];

            [device unlockForConfiguration];

        } else {

            id delegate = [self delegate];

            if ([delegate respondsToSelector:@selector(acquiringDeviceLockFailedWithError:)]) {

                [delegate acquiringDeviceLockFailedWithError:error];

            }

        }        

    }

}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM