public override void StartCapture(BackgroundWorker bw) { ManagedImage m_image = new ManagedImage(); ManagedImage m_converted = new ManagedImage(); try { //camera.StopCapture(); camera.EndAcquisition(); } catch (SpinnakerException ex) { if (!ex.Message.Contains("Camera is not started")) { throw; } } //camera.StartCapture(); camera.BeginAcquisition(); PtGreyCameraImage helper = new PtGreyCameraImage(); helper.converted = m_converted; helper.raw = m_image; helper.cam = camera; bw.RunWorkerAsync(helper); }
public override BitmapSource GetImage(DoWorkEventArgs e) { PtGreyCameraImage helper = (PtGreyCameraImage)e.Argument; BitmapSource source; //helper.cam.RetrieveBuffer(helper.raw); //helper.raw.ConvertToBitmapSource(helper.converted); IManagedImage managedImage = helper.cam.GetNextImage(); if (managedImage.IsIncomplete) { Console.WriteLine("GetNextImage Incompleted"); return(null); } managedImage.ConvertToBitmapSource(PixelFormatEnums.BGR8, helper.converted); if ((Properties.Settings.Default.CropHeight == 0 && Properties.Settings.Default.CropWidth == 0) || (Properties.Settings.Default.CropHeight + Properties.Settings.Default.CropTop > helper.converted.bitmapsource.Height) || (Properties.Settings.Default.CropWidth + Properties.Settings.Default.CropLeft > helper.converted.bitmapsource.Width) ) { source = helper.converted.bitmapsource; CropImageWidth = 0; CropImageHeight = 0; } else { source = new CroppedBitmap(helper.converted.bitmapsource, new System.Windows.Int32Rect((int)Properties.Settings.Default.CropLeft, (int)Properties.Settings.Default.CropTop, (int)(Properties.Settings.Default.CropWidth == 0 ? helper.converted.bitmapsource.Width : Properties.Settings.Default.CropWidth), (int)(Properties.Settings.Default.CropHeight == 0 ? helper.converted.bitmapsource.Height : Properties.Settings.Default.CropHeight))); CropImageWidth = source.Width; CropImageHeight = source.Height; } source.Freeze(); ImageWidth = helper.converted.bitmapsource.Width; ImageHeight = helper.converted.bitmapsource.Height; managedImage.Release(); return(source); }