public async Task TakePictureWithInMemoryHandler() { TestHelper.BeginTest("TakePictureWithInMemoryHandler"); TestHelper.SetConfigurationDefaults(); var imgCaptureHandler = new InMemoryCaptureHandler(); using (var preview = new MMALNullSinkComponent()) using (var imgEncoder = new MMALImageEncoder(true)) { Fixture.MMALCamera.ConfigureCameraSettings(); var portConfig = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, 90); imgEncoder.ConfigureOutputPort(portConfig, imgCaptureHandler); // Create our component pipeline. Fixture.MMALCamera.Camera.StillPort .ConnectTo(imgEncoder); Fixture.MMALCamera.Camera.PreviewPort .ConnectTo(preview); // Camera warm up time await Task.Delay(2000); await Fixture.MMALCamera.ProcessAsync(Fixture.MMALCamera.Camera.StillPort); Assert.True(imgCaptureHandler.WorkingData.Count > 0); } }
public async Task <byte[]> TakePicture(int quality) { using (var jpegCaptureHandler = new InMemoryCaptureHandler()) using (var imageEncoder = new MMALImageEncoder()) using (var nullSink = new MMALNullSinkComponent()) { lock (this) { MMALCamera.Instance.ConfigureCameraSettings(); } MMALPortConfig portConfigJPEG = new MMALPortConfig(MMALEncoding.JPEG, MMALEncoding.I420, quality: quality); imageEncoder.ConfigureOutputPort(portConfigJPEG, jpegCaptureHandler); MMALCamera.Instance.Camera.StillPort.ConnectTo(imageEncoder); MMALCamera.Instance.Camera.PreviewPort.ConnectTo(nullSink); await MMALCamera.Instance.ProcessAsync(MMALCamera.Instance.Camera.StillPort); return(jpegCaptureHandler.WorkingData.ToArray()); } }