private void GrabImageTimer(object sender, System.Timers.ElapsedEventArgs e) { // 响应停止请求 if (m_reqStop == 0) { m_reqStop = 1; myTimer.Enabled = false; } if (R3(m_ip).getStatus() == CAM_STATUS.CAM_IS_STARTED && R3(m_ip).isGrabbed()) { CSImgT imgTable = new CSImgT(); if (R3(m_ip).getImageData(imgTable) == CAM_STATUS.All_OK) { Bitmap imgGray; // 读取图片 convert image to show var mode = GetGrabMode(); if (!imgTable.has(mode)) { return; } switch (mode) { case DataNames.SEN: imgGray = BuiltGrayBitmap( imgTable.getDataByte(mode), imgTable.getS_cols(), imgTable.getS_rows() ); break; case DataNames.REF: case DataNames.SCA: case DataNames.REF_CAL: case DataNames.SCA_CAL: case DataNames.REF2: case DataNames.SCA2: case DataNames.REF2_CAL: case DataNames.SCA2_CAL: imgGray = BuiltGrayBitmap( imgTable.getDataByte(mode), imgTable.getR_cols(), imgTable.getR_rows() ); break; case DataNames.RAN: case DataNames.RAN2: imgGray = BuiltGrayBitmap( imgTable.getDataWord(mode), imgTable.getR_cols(), imgTable.getR_rows() ); break; case DataNames.RAN_CAL: case DataNames.RAN2_CAL: imgGray = BuiltGrayBitmap( imgTable.getDataFloat(mode), imgTable.getR_cols(), imgTable.getR_rows() ); break; default: imgTable.Dispose(); return; } // 显示图片 Show Image // Code below will cost a lot of memory. // This is a side effect of C# gc. #if true System.Drawing.Image imgShow = System.Drawing.Image.FromHbitmap(imgGray.GetHbitmap()); pictureBox1.BackgroundImage = imgShow.GetThumbnailImage(pictureBox1.Size.Width, pictureBox1.Size.Height, null, IntPtr.Zero); imgShow.Dispose(); imgGray.Dispose(); imgShow = null; imgGray = null; GC.Collect(); GC.WaitForPendingFinalizers(); #endif lock (m_imgLocker) { m_lastImg._deepCopy(imgTable); } // 响应停止请求 if (m_reqStop == 0) { m_reqStop = 1; myTimer.Enabled = false; } // show ID wFlog(imgTable.get_ID().ToString()); } imgTable.Dispose(); GC.Collect(); GC.WaitForPendingFinalizers(); } }