我试着用iPhone用AVFoundation捕捉图片,但是我有一些困难要找到我需要的东西。我创建了一个AVCaptureSession并将预设添加到AVCaptureSessionPresetHigh中。self.session.sessionPreset = AVCaptureSessionPresetHigh;
我在视图中显示videoPreviewLayer,我可以用代码捕获图片:
AVCapturePhotoSettings *settings = [AVCapturePhotoSettings photoSettingsWithFormat: @{AVVideoCodecKey:AVVideoCodecJPEG}];
[self.stillImageOutput capturePhotoWithSettings:settings delegate:self]我得到了一张FHD图片(1920x1080),所以这个很好。
但现在我想保持一个良好的显示图片,所以保持预设高,但捕获的分辨率640x480。
有可能吗?有什么想法吗?
我试过这个:
NSDictionary *outputSetting = [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithDouble:1280], (id)kCVPixelBufferHeightKey,
[NSNumber numberWithDouble:960], (id)kCVPixelBufferWidthKey,
[NSNumber numberWithUnsignedInt:kCVPixelFormatType_32BGRA], (id)kCVPixelBufferPixelFormatTypeKey,
nil];
AVCapturePhotoSettings *settings = [AVCapturePhotoSettings photoSettingsWithFormat: outputSetting];
[self.stillImageOutput capturePhotoWithSettings:settings delegate:(id)self];但我知道这个错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** +[AVCapturePhotoSettings photoSettingsWithFormat:] Unsupported keys specified: {(
Height,
Width
)}. Supported keys are {(
PixelFormatType
)}'发布于 2019-03-14 16:21:48
当您准备拍照时,请求640x480次输出,如下所示:
let settings = AVCapturePhotoSettings()
let pbpf = settings.availablePreviewPhotoPixelFormatTypes[0]
settings.previewPhotoFormat = [
kCVPixelBufferPixelFormatTypeKey as String : pbpf,
kCVPixelBufferWidthKey as String : 640,
kCVPixelBufferHeightKey as String : 480当您拍照时,将settings传递进来,如下所示:
output.capturePhoto(with: settings, delegate: self)辅助输出将作为委托方法中的照片的previewCGImageRepresentation返回给您。
https://stackoverflow.com/questions/55150887
复制相似问题