0

not sure what I am doing wrong, I wanna create a simple custom camera, I'm creating the AVCapturePhotoOutput attaching it to AVCaptureSession, then creating AVCapturePhotoSettings with minimum settings to make taking a picture work, see code below.

I get exception kCVPixelBufferPixelFormatTypeKey is not being define but it is indeed in the NSDictionary I am passing.

I need some light here, thanks

    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);
    }
RollRoll
  • 8,133
  • 20
  • 76
  • 135
  • I solved the issue by passing: settings.PreviewPhotoFormat = new NSDictionary(CVPixelBuffer.PixelFormatTypeKey, settings.AvailablePreviewPhotoPixelFormatTypes[0]); but not sure why the first attempt didn't work – RollRoll Dec 04 '17 at 02:21

1 Answers1

1

It is because kCVPixelBufferPixelFormatTypeKey is not available in Xamarin.

We should use CVPixelBuffer.PixelFormatTypeKey here . It will be convert to kCVPixelBufferPixelFormatTypeKey automatically when compiling.

The same reason for kCVPixelBufferWidthKey and kCVPixelBufferHeightKey , the api is CVPixelBuffer.WidthKey and CVPixelBuffer.HeightKey in Xamarin.iOS.

ColeX
  • 14,062
  • 5
  • 43
  • 240