【问题标题】:AVCapturePhotoSettings not accepting accept NSDictionary elementAVCapturePhotoSettings 不接受接受 NSDictionary 元素
【发布时间】:2017-12-04 02:15:21
【问题描述】:

不知道我做错了什么,我想创建一个简单的自定义相机,我正在创建 AVCapturePhotoOutput 并将其附加到 AVCaptureSession,然后使用最低设置创建 AVCapturePhotoSettings 以使拍照工作,请参见下面的代码。

我得到异常 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);
    }

【问题讨论】:

  • 我通过传递解决了这个问题: settings.PreviewPhotoFormat = new NSDictionary(CVPixelBuffer.PixelFormatTypeKey, settings.AvailablePreviewPhotoPixelFormatTypes[0]);但不确定为什么第一次尝试没有成功

标签: xamarin xamarin.ios ios-camera


【解决方案1】:

这是因为 kCVPixelBufferPixelFormatTypeKey 在 Xamarin 中不可用。

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

kCVPixelBufferWidthKey 和 kCVPixelBufferHeightKey 的原因相同,API 在 Xamarin.iOS 中是 CVPixelBuffer.WidthKey 和 CVPixelBuffer.HeightKey。

【讨论】:

    猜你喜欢
    • 2013-09-24
    • 1970-01-01
    • 1970-01-01
    • 2016-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-01
    相关资源
    最近更新 更多