【问题标题】:AVCapturePhotoSettings error in ios 10?ios 10 中的 AVCapturePhotoSettings 错误?
【发布时间】:2017-04-30 13:48:15
【问题描述】:

我的应用程序使用相机然后压缩图像 JPEG,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

有人知道怎么用吗?谢谢。

【问题讨论】:

    标签: ios avcapturesession avcapturephotooutput


    【解决方案1】:

    你需要在[self.photoOutput capturePhotoWithSettings:delegate:];之前调用[self.session addOutput:];

    试试:

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

    【讨论】:

      【解决方案2】:

      建立连接的顺序很重要。

      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];
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-01-22
        • 1970-01-01
        • 2017-02-14
        • 1970-01-01
        • 2017-12-25
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多