private void TIS_ImageAvailable(object sender, ICImagingControl.ImageAvailableEventArgs e) { try { //Util.Notify(string.Format("相机{0}收到图像", cameraIndex)); if (ignoreImage) { return; } //HTuple startTime; HOperatorSet.CountSeconds(out startTime); // Acquire the image from the camera. Only show the latest image. The camera may acquire images faster than the images can be displayed. ImageBuffer ImgBuffer = e.ImageBuffer; // Reduce the number of displayed images to a reasonable amount if the camera is acquiring images very fast. //if (!stopWatch.IsRunning || stopWatch.ElapsedMilliseconds > 33) { //stopWatch.Restart(); //if (hPylonImage != null && hPylonImage.IsInitialized()) //{ // hPylonImage.Dispose(); //} hPylonImage = new HImage(); if (ImgBuffer.GetIntPtr() == IntPtr.Zero) { Util.Notify(string.Format("相机{0}数据损坏,采集失败", cameraIndex)); return; } if (camera.MemoryCurrentGrabberColorformat == ICImagingControlColorformats.ICY8) { hPylonImage.GenImage1("byte", ImgBuffer.Size.Width, ImgBuffer.Size.Height, ImgBuffer.GetImageDataPtr()); HImage imgTmp = hPylonImage.MirrorImage("row"); hPylonImage.Dispose(); hPylonImage = imgTmp; } else if (camera.MemoryCurrentGrabberColorformat == ICImagingControlColorformats.ICRGB32) { //allocate the m_stream_size amount of bytes in non-managed environment hPylonImage.GenImageInterleaved(ImgBuffer.GetImageDataPtr(), "rgb", ImgBuffer.Size.Width, ImgBuffer.Size.Height, -1, "byte", ImgBuffer.Size.Width, ImgBuffer.Size.Height, 0, 0, -1, 0); } else { Util.Notify(string.Format("相机{0}编码格式不正确", cameraIndex)); } TrigerImageEvent(); } } catch (System.ArgumentException ex) { Util.WriteLog(this.GetType(), ex); Util.Notify(string.Format("相机{0}图像数据包丢失", cameraIndex)); } catch (Exception ex) { Util.WriteLog(this.GetType(), ex); Util.Notify(string.Format("相机{0}图像数据返回出现异常", cameraIndex)); } }