Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
__iPhone 7上的availableRawPhotoPixelFormatTypes为空;和iOS11_Ios_Swift_Avfoundation_Rawimage - Fatal编程技术网

__iPhone 7上的availableRawPhotoPixelFormatTypes为空;和iOS11

__iPhone 7上的availableRawPhotoPixelFormatTypes为空;和iOS11,ios,swift,avfoundation,rawimage,Ios,Swift,Avfoundation,Rawimage,我正试图用AVFoundation捕获原始文件。但是,我在\uuu可用的WPhotopixelFormatTypes中得到了空数组 这是我的片段 if self._photoOutput == nil { self._photoOutput = AVCapturePhotoOutput() print(self._photoOutput!.__availableRawPhotoPixelFormatTypes) } 并且输出为空数组[] 这可能是什么原因造成的 以下三个因素将导

我正试图用AVFoundation捕获原始文件。但是,我在
\uuu可用的WPhotopixelFormatTypes中得到了空数组

这是我的片段

if self._photoOutput == nil {
    self._photoOutput = AVCapturePhotoOutput()
    print(self._photoOutput!.__availableRawPhotoPixelFormatTypes)
}
并且输出为空数组
[]


这可能是什么原因造成的

以下三个因素将导致
availableRawPhotoPixelFormatTypes
数组为空:

  • 在使用视频源将您的
    \u photoOutput
    添加到
    AVCaptureSession
    之前,您正在阅读
    availableRawPhotoPixelFormatTypes
    属性

  • 您正在使用双摄像头输入。如果是这样,则无法捕获原始图像

  • 您正在使用前摄像头。如果是这样,则无法捕获原始图像

  • 下面是一本优秀的Apple指南中的一些修改后的示例代码(请参见下面的链接)。我从几个地方复制了一些内容,并对其进行了轻微的更新,以简洁、简单和更好的概述:

    let session = AVCaptureSession()
    let photoOutput = AVCapturePhotoOutput()
    
    private func configureSession() {
        // Get camera device.
        guard let videoCaptureDevice = AVCaptureDevice.default(.builtInWideAngleCamera, for: .video, position: .back) else {
            print("Unable to get camera device.")
            return
        }
        // Create a capture input.
        guard let videoInput = try? AVCaptureDeviceInput(device: videoCaptureDevice) else {
            print("Unable to obtain video input for default camera.")
            return
        }
    
        // Make sure inputs and output can be added to session.
        guard session.canAddInput(videoInput) else { return }
        guard session.canAddOutput(photoOutput) else { return }
    
        // Configure the session.
        session.beginConfiguration()
        session.sessionPreset = .photo
        session.addInput(videoInput)
        // availableRawPhotoPixelFormatTypes is empty.
        session.addOutput(photoOutput)
        // availableRawPhotoPixelFormatTypes should not be empty.
        session.commitConfiguration()
    }
    
    private func capturePhoto() {
        // Photo settings for RAW capture.
        let rawFormatType = kCVPixelFormatType_14Bayer_RGGB
        // At this point the array should not be empty (session has been configured).
        guard photoOutput.availableRawPhotoPixelFormatTypes.contains(NSNumber(value: rawFormatType).uint32Value) else {
            print("No available RAW pixel formats")
            return
        }
    
        let photoSettings = AVCapturePhotoSettings(rawPixelFormatType: rawFormatType)
        photoOutput.capturePhoto(with: photoSettings, delegate: self)
    }
    
    // MARK: - AVCapturePhotoCaptureDelegate methods
    
    func photoOutput(_ output: AVCapturePhotoOutput,
                     didFinishProcessingRawPhoto rawSampleBuffer: CMSampleBuffer?,
                     previewPhoto previewPhotoSampleBuffer: CMSampleBuffer?,
                     resolvedSettings: AVCaptureResolvedPhotoSettings,
                     bracketSettings: AVCaptureBracketedStillImageSettings?,
                     error: Error?) {
        guard error == nil, let rawSampleBuffer = rawSampleBuffer else {
            print("Error capturing RAW photo:\(error)")
            return
        }
        // Do something with the rawSampleBuffer.
    }
    
    苹果的照片捕获指南:

    可用的wphotopixelformatypes属性: )

    iPhone摄像头功能:
    对于@Thomas的回答,有一个补充:


    如果更改
    AVCaptureDevice.activeFormat
    AVCaptureSession.sessionPreset
    将自动设置为
    inputPriority
    。在这种情况下,
    availableRawPhotoPixelFormatTypes
    也将是空的。

    除了解释问题是什么之外,还可以提供一些代码来帮助解决问题。我意识到这可能与我尝试使用前置摄像头有关。我明白了,这是有意义的。我将更新答案以帮助未来的读者。我尝试使用除最大可用性以外的维度设置捕获设备格式。WPhotopixelFormatTypes也将为空。iOS 13.3是的,这个答案是正确的。我的解决方案是设置
    会话。会话再次按
    。photo
    将起作用这是Apple文档中的一个大漏洞。我不明白为什么availableRawPhotoPixelFormatTypes一直显示为没有记录。非常感谢。