- 问题
后面写了拍照、扫码、录视频的性能,后面要求性能实现即可,前面发现画质不够
- 思路
可能起因剖析:
1.AVCaptureSession 设置输入格局会影响画质清晰度
2. 拍照中并未做聚焦 / 曝光解决, 或 聚焦 / 曝光设置参数导致含糊
-
解决
针对起因 1,列举如下 sessionPreset 对应的像素 (height *width):
AVCaptureSessionPresetHigh 1920*1080 AVCaptureSessionPresetMedium 480*360 AVCaptureSessionPresetLow 192*144 AVCaptureSessionPresetPhoto 4032*3024 AVCaptureSessionPreset352x288 352*288 AVCaptureSessionPreset640x480 640*480 AVCaptureSessionPreset1280x720 1280*720 AVCaptureSessionPreset1920x1080 1920*1080 AVCaptureSessionPreset3840x2160 3840*2160 AVCaptureSessionPresetiFrame960x540 960*540 AVCaptureSessionPresetiFrame1280x720 1280*720 AVCaptureSessionPresetInputPriority 1920*1080
按需来设置该参数
针对起因 2,聚焦 / 曝光设置:
/* 必须先设置聚焦地位,再设定聚焦形式 */ CGRect rectLayer = self.preView.frame; CGPoint ccenter = CGPointMake((rectLayer.origin.x + rectLayer.size.width) / 2, (rectLayer.origin.y + rectLayer.size.height) / 2); CGPoint cpoint = [self.preView captureDevicePointForPoint:ccenter]; AVCaptureDevice *devices= [self.dInput device]; [self.session beginConfiguration]; [devices lockForConfiguration:nil]; // 设置聚焦点的地位 if ([devices isFocusPointOfInterestSupported]) {[devices setFocusPointOfInterest:cpoint]; } // 设置聚焦模式 if ([devices isFocusModeSupported:AVCaptureFocusModeContinuousAutoFocus]) {[devices setFocusMode:AVCaptureFocusModeContinuousAutoFocus]; } // 设置曝光点的地位 if ([devices isExposurePointOfInterestSupported]) {[devices setExposurePointOfInterest:cpoint]; } // 设置曝光模式 if ([devices isExposureModeSupported:AVCaptureExposureModeContinuousAutoExposure]) {[devices setExposureMode:AVCaptureExposureModeContinuousAutoExposure]; } [device unlockForConfiguration]; [self.session commitConfiguration];
其中聚焦模式 跟曝光模式的设置很有意思:
typedef NS_ENUM(NSInteger, AVCaptureFocusMode) { // 将焦点锁定在镜头的以后地位 AVCaptureFocusModeLocked = 0, // 设施应主动对焦一次,而后将对焦模式更改为 AVCaptureFocusModeLocked AVCaptureFocusModeAutoFocus = 1, // 设施应在须要时主动对焦 AVCaptureFocusModeContinuousAutoFocus = 2, } typedef NS_ENUM(NSInteger, AVCaptureExposureMode) { // 将曝光锁定在其以后值 AVCaptureExposureModeLocked = 0, // 主动调整一次曝光,而后将曝光模式更改为 AVCaptureExposureModeLocked AVCaptureExposureModeAutoExpose = 1, // 在须要时主动调整曝光 AVCaptureExposureModeContinuousAutoExposure = 2, // 仅依据用户提供的 ISO,DurationDuration 值来调整曝光 AVCaptureExposureModeCustom API_AVAILABLE(macos(10.15), ios(8.0)) = 3, }
当我设置聚焦模式 = AVCaptureFocusModeAutoFocus,曝光模式 = AVCaptureExposureModeAutoExpose,会有聚焦的过程,但跟零碎拍照有差距。
调试下参数别离为 ContinuousAuto 模式后,画质清晰度跟零碎拍照差不多了。
- 完结