• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

ios - 如何更改前置摄像头的曝光?

[复制链接]
菜鸟教程小白 发表于 2022-12-13 10:09:53 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题

经过反复试验,我意识到 iPhone 6 及以下机型的前置摄像头不支持点按对焦。但是有没有办法改变曝光?我已经尝试使用下面的代码,但没有任何反应。使用这种方法后置摄像头对焦很好,但是当我切换到前置摄像头时没有任何反应。 (我使用的是自定义相机)。

任何帮助将不胜感激!

- (void) focusAtPointCGPoint)point

{
AVCaptureDevice *device = [deviceInput device];

NSArray * inputs = session.inputs;
for (AVCaptureDeviceInput * INPUT in inputs) {
    AVCaptureDevice * Device = INPUT.device ;
    if ([ Device hasMediaType:AVMediaTypeVideo ]) {
        AVCaptureDevicePosition position = Device.position;


        if (position == AVCaptureDevicePositionFront)
        {
            //code for setting exposure
            if ([device isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) {
                NSError *error;

                [device lockForConfiguration:&error];

                CGPoint exposurePoint = point;
                [device setExposurePointOfInterest:exposurePoint];
                [device setExposureMode:AVCaptureExposureModeContinuousAutoExposure];
                [device unlockForConfiguration];
            }

        }
        else if(position == AVCaptureDevicePositionBack)
        {
           //code for focusing 
        }

    }
} 
}



Best Answer-推荐答案


它可以帮助你。

override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {

            let screenSize = cameraView.bounds.size

            let frameSize:CGSize = view.frame.size


            if let touchPoint = touches.first {

                var location:CGPoint = touchPoint.locationInView(cameraView)

                print("Tap Location : X: \(location.x), Y: \(location.y)")

                if cameraManager.cameraDevice == .Front {
                    print("Front camera is used")

                    location.x = frameSize.width - location.x;
                }
                else {
                    print("Back camera is used")
                }

    //            let x = location.y / frameSize.height
                let x = location.x / frameSize.width
                let y = 1.0 - (location.x / frameSize.width)

                let focusPoint = CGPoint(x: x, y: y)

                print("OINT : X: \(x), Y: \(y)")

    //            let captureDevice = AVCaptureDevice.devices().first as? AVCaptureDevice

                let captureDevice = (AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo) as! [AVCaptureDevice]).filter{$0.position == .Front}.first

                if let device = captureDevice {
                    do {
                        try device.lockForConfiguration()

                        let focusSupport:Bool = device.focusPointOfInterestSupported
                        let exposureSupport:Bool = device.exposurePointOfInterestSupported

                        print(" AVCaptureFocusMode.AutoFocus:  \(device.isFocusModeSupported(AVCaptureFocusMode.AutoFocus))")
                        print(" AVCaptureFocusMode.ContinuousAutoFocus:  \(device.isFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus))")
                        print(" AVCaptureFocusMode.Locked:  \(device.isFocusModeSupported(AVCaptureFocusMode.Locked))")

                        print(" AVCaptureExposureMode.AutoExpose:  \(device.isExposureModeSupported(AVCaptureExposureMode.AutoExpose))")
                        print(" AVCaptureExposureMode.ContinuousAutoExposure:  \(device.isExposureModeSupported(AVCaptureExposureMode.ContinuousAutoExposure))")
                        print(" AVCaptureExposureMode.Locked:  \(device.isExposureModeSupported(AVCaptureExposureMode.Locked))")


                        if focusSupport  {

                            print("focusPointOfInterestSupported: \(focusSupport)")

                            device.focusPointOfInterest = focusPoint

                            // device.focusMode = .ContinuousAutoFocus
                            device.focusMode = .AutoFocus
                            // device.focusMode = .Locked


                            print("Focus point was set successfully")
                        }
                        else{
                            print("focusPointOfInterestSupported is not supported: \(focusSupport)")
                        }


                        if exposureSupport {

                            print("exposurePointOfInterestSupported: \(exposureSupport)")

                            device.exposurePointOfInterest = focusPoint

                            device.exposureMode = AVCaptureExposureMode.ContinuousAutoExposure

                            print("Exposure point was set successfully")
                        }
                        else{
                            print("exposurePointOfInterestSupported is not supported: \(exposureSupport)")
                        }

                        device.unlockForConfiguration()

                    }
                    catch {
                        // just ignore
                        print("Focus point error")
                    }
                }

关于ios - 如何更改前置摄像头的曝光?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32298450/

回复

使用道具 举报

懒得打字嘛,点击右侧快捷回复 【右侧内容,后台自定义】
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注0

粉丝2

帖子830918

发布主题
阅读排行 更多
广告位

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap