// 获取设备名 为 name 的设备 返回数量 public int CameraCount(string name) { m_hCamera = -1; int count = 0; int nRet; /*创建设备列表*/ System.GC.Collect(); CameraOperator_HK.EnumDevices(MyCamera.MV_GIGE_DEVICE | MyCamera.MV_USB_DEVICE, ref m_pDeviceList); //在窗体列表中显示设备名 for (int i = 0; i < m_pDeviceList.nDeviceNum; i++) { MyCamera.MV_CC_DEVICE_INFO device = (MyCamera.MV_CC_DEVICE_INFO)Marshal.PtrToStructure(m_pDeviceList.pDeviceInfo[i], typeof(MyCamera.MV_CC_DEVICE_INFO)); if (device.nTLayerType == MyCamera.MV_GIGE_DEVICE) { IntPtr buffer = Marshal.UnsafeAddrOfPinnedArrayElement(device.SpecialInfo.stGigEInfo, 0); MyCamera.MV_GIGE_DEVICE_INFO gigeInfo = (MyCamera.MV_GIGE_DEVICE_INFO)Marshal.PtrToStructure(buffer, typeof(MyCamera.MV_GIGE_DEVICE_INFO)); //if (name == gigeInfo.chModelName) //{ bitmapInfo.CameraName = name; m_hCamera = i; //} } } count = (int)m_pDeviceList.nDeviceNum; return(count); }
//public MyCamera.MV_FRAME_OUT_INFO stFrameInfo; public void OnMVImageReadyEventCallback() { lock (obj) { try { byte[] buffer = new byte[SizeMax.Width * SizeMax.Height * 3]; IntPtr pData = Marshal.UnsafeAddrOfPinnedArrayElement(buffer, 0); UInt32 nDataLen = 0; //stFrameInfo = new MyCamera.MV_FRAME_OUT_INFO(); stFrameInfo = new MyCamera.MV_FRAME_OUT_INFO_EX(); int nRet; //超时获取一帧,超时时间为1秒 // nRet = GetOneFrame(pData, ref nDataLen, (uint)SizeMax.Width * (uint)SizeMax.Height * 3, ref stFrameInfo); nRet = GetImageBGR(pData, (uint)SizeMax.Width * (uint)SizeMax.Height * 3, ref stFrameInfo); if (MyCamera.MV_OK == nRet) { if (m_bitmap != null) { /* Update the bitmap with the image data. */ CameraOperator_HK.UpdateBitmap(m_bitmap, buffer, stFrameInfo.nWidth, stFrameInfo.nHeight, true); /* To show the new image, request the display control to update itself. */ } else /* A new bitmap is required. */ { CameraOperator_HK.CreateBitmap(ref m_bitmap, stFrameInfo.nWidth, stFrameInfo.nHeight, true); CameraOperator_HK.UpdateBitmap(m_bitmap, buffer, stFrameInfo.nWidth, stFrameInfo.nHeight, true); //* Provide the display control with the new bitmap. This action automatically updates the display. */ } bitmapInfo.m_Bitmap = (Bitmap)m_bitmap.Clone(); if (ImageReady != null) { ImageReady(bitmapInfo, IsContinuousShot); } } } catch (Exception e) { } } }