【问题标题】:How to implement tap-to-focus, tap-to-set-exposure如何实现点击对焦、点击设置曝光
【发布时间】:2015-08-07 21:44:36
【问题描述】:

我正在构建此代码以供将来学习和娱乐。它应该打开相机并启用触摸焦点。它适用于后置摄像头,但当我将其翻转到前置摄像头时没有任何反应。我已经搜索了很多,但找不到任何解决该问题的代码。谁能用代码一步一步地告诉我如何使触摸焦点也可以在前置摄像头视图中工作?

下面是焦点功能:

- (void) focus:(CGPoint) aPoint{



    AVCaptureDevice *device = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];
    if([device isFocusPointOfInterestSupported] &&
       [device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
        CGRect screenRect = [[UIScreen mainScreen] bounds];
        double screenWidth = screenRect.size.width;
        double screenHeight = screenRect.size.height;
        double focus_x = aPoint.x/screenWidth;
        double focus_y = aPoint.y/screenHeight;
        if([device lockForConfiguration:nil]) {
            if([self.delegate respondsToSelector:@selector(scanViewController:didTapToFocusOnPoint:)]) {
                [self.delegate scanViewController:self didTapToFocusOnPoint:aPoint];
            }
            [device setFocusPointOfInterest:CGPointMake(focus_x,focus_y)];
            [device setFocusMode:AVCaptureFocusModeAutoFocus];
            if ([device isExposureModeSupported:AVCaptureExposureModeAutoExpose]){
                [device setExposureMode:AVCaptureExposureModeAutoExpose];
            }
            [device unlockForConfiguration];
        }
    }
}

完整的源代码可以在这里找到:

https://gist.github.com/Alex04/6976945

更新:

if ([device isExposurePointOfInterestSupported])
{
    [device lockForConfiguration:&error];
    [device setExposurePointOfInterest:aPoint];
    if ([device isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure])
    {
        [device setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
    }
    [device setWhiteBalanceMode:AVCaptureWhiteBalanceModeContinuousAutoWhiteBalance];
    [device unlockForConfiguration];
}

【问题讨论】:

    标签: ios objective-c camera avfoundation


    【解决方案1】:

    我认为前置摄像头在任何 iPhone 上都不支持点击对焦。您可以通过检查AVCaptureDevicefocusPointOfInterestSupported 属性来检查支持。

    如果要实现点击曝光,请检查设备的exposurePointOfInterestSupported 属性。如果设备支持该功能,请设置exposurePointOfInterest 属性以使用它。

    【讨论】:

    • 我想让它模仿真正的 iPhone 相机。当您在使用前置摄像头时触摸任何地方时,它会改变光线的种类......但也不知道该怎么做
    • 能否请您逐步提供代码如何植入我链接到的源代码中?但是谢谢你告诉我正确的名字,因为我不知道它的名字
    • 您必须自己尝试实现它。它应该与您已有的代码相似。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-06-02
    • 2016-01-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-03
    相关资源
    最近更新 更多