Ios 如何更改前置摄像头的曝光?
经过反复试验,我发现iPhone 6及以下版本的前置摄像头不支持点击对焦。然而,有没有办法改变曝光?我尝试了下面的代码,但什么也没发生。使用这种方法后摄像头的焦距很好,但当我切换到前摄像头时,什么也没有发生。(我使用的是定制相机) 任何帮助都将不胜感激Ios 如何更改前置摄像头的曝光?,ios,camera,focus,avfoundation,Ios,Camera,Focus,Avfoundation,经过反复试验,我发现iPhone 6及以下版本的前置摄像头不支持点击对焦。然而,有没有办法改变曝光?我尝试了下面的代码,但什么也没发生。使用这种方法后摄像头的焦距很好,但当我切换到前摄像头时,什么也没有发生。(我使用的是定制相机) 任何帮助都将不胜感激 - (void) focusAtPoint:(CGPoint)point { AVCaptureDevice *device = [deviceInput device]; NSArray * inputs = session.inputs;
- (void) focusAtPoint:(CGPoint)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
}
}
}
}
它可以帮助你
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("POINT : 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")
}
}
覆盖函数触摸开始(触摸:设置,withEvent事件:UIEvent?){
让screenSize=cameraView.bounds.size
let frameSize:CGSize=view.frame.size
如果让touchPoint=touchs.first{
变量位置:CGPoint=touchPoint.locationInView(cameraView)
打印(“点击位置:X:\(Location.X),Y:\(Location.Y)”)
如果cameraManager.cameraDevice==.Front{
打印(“使用前摄像头”)
location.x=frameSize.width-location.x;
}
否则{
打印(“使用后摄像头”)
}
//设x=位置.y/框架尺寸.height
设x=location.x/frameSize.width
设y=1.0-(location.x/frameSize.width)
设focusPoint=CGPoint(x:x,y:y)
打印(“点:X:\(X),Y:\(Y)”)
//设captureDevice=AVCaptureDevice.devices()。首先为?AVCaptureDevice
让captureDevice=(AVCaptureDevice.devicesWithMediaType(AVMediaTypeVideo)作为![AVCaptureDevice])。筛选器{$0.position=.Front}。首先
如果let device=captureDevice{
做{
请尝试device.lockForConfiguration()
let focusSupport:Bool=device.focusPointOfInterestSupported
让exposureSupport:Bool=device.exposurePointOfInterestSupported
打印(“AVCaptureFocusMode.AutoFocus:\(device.isFocusModeSupported(AVCaptureFocusMode.AutoFocus))”)
打印(“AVCaptureFocusMode.ContinuousAutoFocus:\(设备.isFocusModeSupported(AVCaptureFocusMode.ContinuousAutoFocus)))
打印(“AVCaptureFocusMode.Locked:\(device.isFocusModeSupported(AVCaptureFocusMode.Locked)))
打印(“AVCaptureExposureMode.AutoExposure:\(设备.IsExposureMode支持(AVCaptureExposureMode.AutoExpose)))
打印(“AVCaptureExposureMode.ContinuousAutoExposure:\(设备.IsExposureMode支持(AVCaptureExposureMode.ContinuousAutoExposure)))
打印(“AVCaptureExposureMode.Locked:\(device.isExposureModeSupported(AVCaptureExposureMode.Locked)))
如果聚焦支持{
打印(“focusPointOfInterestSupported:\(focusSupport)”)
device.focusPointOfInterest=焦点点
//device.focusMode=.ContinuousAutoFocus
device.focusMode=.AutoFocus
//device.focusMode=.Locked
打印(“焦点设置成功”)
}
否则{
打印(“不支持focusPointOfInterestSupported:\(focusSupport)”)
}
如果公开支持{
打印(“exposurePointOfInterestSupported:\(exposureSupport)”)
device.exposurePointOfInterest=焦点点
device.exposureMode=AVCaptureExposureMode.ContinuousAutoExposure
打印(“曝光点设置成功”)
}
否则{
打印(“不支持exposurePointOfInterestSupported:\(exposureSupport)”)
}
device.unlockForConfiguration()
}
抓住{
//不管
打印(“焦点错误”)
}
}
您找到了解决方案吗?您也能用前置摄像头对焦吗?