public void UpdateCameraOption(CameraOptions option) { if (CameraOption == option) { return; } CameraOption = option; var cameraPosition = (CameraOption == CameraOptions.Front) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back; var device = GetCameraForOrientation(cameraPosition); ConfigureCameraForDevice(device); CaptureSession.BeginConfiguration(); CaptureSession.RemoveInput(captureDeviceInput); captureDeviceInput = AVCaptureDeviceInput.FromDevice(device); CaptureSession.AddInput(captureDeviceInput); CaptureSession.CommitConfiguration(); }
public void CameraButtonTapped() { var devicePosition = captureDeviceInput.Device.Position; if (devicePosition == AVCaptureDevicePosition.Front) { devicePosition = AVCaptureDevicePosition.Back; } else { devicePosition = AVCaptureDevicePosition.Front; } var device = GetCameraForOrientation(devicePosition); // ConfigureCameraForDevice(device); CaptureSession.BeginConfiguration(); CaptureSession.RemoveInput(captureDeviceInput); captureDeviceInput = AVCaptureDeviceInput.FromDevice(device); CaptureSession.AddInput(captureDeviceInput); CaptureSession.CommitConfiguration(); }
private void Initialize() { //Pinchジェスチャ登録 SetPinchGesture(); //デバイス設定 var videoDevices = AVCaptureDevice.DevicesWithMediaType(AVMediaType.Video); var cameraPosition = (cameraOptions == CameraOptions.Front) ? AVCaptureDevicePosition.Front : AVCaptureDevicePosition.Back; MainDevice = videoDevices.FirstOrDefault(d => d.Position == cameraPosition); NSError device_error; MainDevice.LockForConfiguration(out device_error); if (device_error != null) { Console.WriteLine($"Error: {device_error.LocalizedDescription}"); MainDevice.UnlockForConfiguration(); return; } //フレームレート設定 MainDevice.ActiveVideoMinFrameDuration = new CMTime(1, 24); MainDevice.UnlockForConfiguration(); if (MainDevice == null) { return; } //max zoom MaxZoom = (float)Math.Min(MainDevice.ActiveFormat.VideoMaxZoomFactor, 6); //入力設定 NSError error; Input = new AVCaptureDeviceInput(MainDevice, out error); CaptureSession.AddInput(Input); //出力設定 Output = new AVCaptureVideoDataOutput(); //フレーム処理用 Queue = new DispatchQueue("myQueue"); Output.AlwaysDiscardsLateVideoFrames = true; Recorder = new OutputRecorder() { Camera = Camera }; Output.SetSampleBufferDelegate(Recorder, Queue); var vSettings = new AVVideoSettingsUncompressed(); vSettings.PixelFormatType = CVPixelFormatType.CV32BGRA; Output.WeakVideoSettings = vSettings.Dictionary; CaptureSession.AddOutput(Output); if (IsPreviewing) { CaptureSession.StartRunning(); } }