1

我的应用程序使用相机然后压缩图像 JPEG,ios 版本 < 10,我使用 AVCaptureStillImageOutput 但 ios 版本 >= 10 我使用 AVCapturePhotoOutput 错误。我有设置代码:`

self.photoOutput = [[AVCapturePhotoOutput alloc] init];
        AVCapturePhotoSettings *photoSettings =
            [AVCapturePhotoSettings photoSettingsWithFormat:@{AVVideoCodecKey : AVVideoCodecJPEG}];

    [self.photoOutput capturePhotoWithSettings:photoSettings delegate:self];
    [self.session addOutput:self.photoOutput];`

我在运行应用程序时遇到问题,应用程序崩溃并出现错误:

[AVCapturePhotoOutput capturePhotoWithSettings:delegate:] No active and enabled video connection

有人知道如何使用这个吗?谢谢。

4

2 回答 2

1

你需要先[self.session addOutput:];打电话[self.photoOutput capturePhotoWithSettings:delegate:];

尝试:

self.photoOutput = [[AVCapturePhotoOutput alloc] init];
        AVCapturePhotoSettings *photoSettings =
            [AVCapturePhotoSettings photoSettingsWithFormat:@{AVVideoCodecKey : AVVideoCodecJPEG}];
[self.photoOutput capturePhotoWithSettings:photoSettings delegate:self];
[self.session addOutput:self.photoOutput];
于 2017-02-16T14:53:14.827 回答
0

建立连接的顺序很重要。

self.photoOutput = [[AVCapturePhotoOutput alloc] init];
AVCapturePhotoSettings *photoSettings = [AVCapturePhotoSettings photoSettingsWithFormat:@{AVVideoCodecKey : AVVideoCodecJPEG}];
if ([self.session canAddOutput: self.photoOutput ]){
     [self.session addOutput: self.photoOutput]
}
[self.photoOutput capturePhotoWithSettings:photoSettings delegate:self];
于 2018-08-01T08:16:13.143 回答