AVCapturePhotoSettings不接受接受NSDictionary元素

时间:2017-12-04 02:15:22

标签: xamarin xamarin.ios ios-camera

不确定我做错了什么,我想创建一个简单的自定义相机,我创建AVCapturePhotoOutput将其附加到AVCaptureSession,然后使用最少设置创建AVCapturePhotoSettings以使图片工作,请参阅下面的代码。 / p>

我得到异常kCVPixelBufferPixelFormatTypeKey没有定义,但确实在我传递的NSDictionary中。

我需要一些亮点,谢谢

    public void TakePicture()
    {
        var output = new AVCapturePhotoOutput();
        _captureSession.AddOutput(output);
        var settings = AVCapturePhotoSettings.Create();
        var previewPixelType = settings.AvailablePreviewPhotoPixelFormatTypes.First();

        var keys = new[]
        {
            new NSString("kCVPixelBufferPixelFormatTypeKey"),
            new NSString("kCVPixelBufferWidthKey"),
            new NSString("kCVPixelBufferHeightKey"),
        };

        var objects = new NSObject[]
        {
            // don't have to be strings... can be any NSObject.
            previewPixelType,
            new NSString("160"),
            new NSString("160")
        };

        var dicionary = new NSDictionary<NSString, NSObject>(keys, objects);
        settings.PreviewPhotoFormat = dicionary;
        output.CapturePhoto(settings,this);
    }

1 个答案:

答案 0 :(得分:0)

这是因为Xamarin中没有kCVPixelBufferPixelFormatTypeKey

我们应该在这里使用CVPixelBuffer.PixelFormatTypeKey 。编译时会自动转换为kCVPixelBufferPixelFormatTypeKey

kCVPixelBufferWidthKeykCVPixelBufferHeightKey相同的原因,api在Xamarin.iOS中为CVPixelBuffer.WidthKeyCVPixelBuffer.HeightKey