public ICogImage Conv_ByteToCog8Grey(byte[] imageData, int width, int height) { // no padding etc. so size calculation // is simple. var rawSize = width * height; var buf = new SafeMalloc(rawSize); // Copy from the byte array into the // previously allocated. memory Marshal.Copy(imageData, 0, buf, rawSize); // Create Cognex Root thing. var cogRoot = new CogImage8Root(); // Initialise the image root, the stride is the // same as the widthas the input image is byte alligned and // has no padding etc. cogRoot.Initialize(width, height, buf, width, buf); // Create cognex 8 bit image. var cogImage = new CogImage8Grey(); // And set the image roor cogImage.SetRoot(cogRoot); return(cogImage); }
/// <summary> /// 显示图片 /// </summary> /// <param name="nHeight">高</param> /// <param name="nWidth">宽</param> /// <param name="pImageBuf">图片数据</param> /// <param name="enPixelType">像素格式</param> public void VisionProDisplay(UInt32 nHeight, UInt32 nWidth, IntPtr pImageBuf, MyCamera.MvGvspPixelType enPixelType) { // ch: 显示 || display try { if (enPixelType == MyCamera.MvGvspPixelType.PixelType_Gvsp_Mono8) { CogImage8Root cogImage8Root = new CogImage8Root(); cogImage8Root.Initialize((Int32)nWidth, (Int32)nHeight, pImageBuf, (Int32)nWidth, null); CogImage8Grey cogImage8Grey = new CogImage8Grey(); cogImage8Grey.SetRoot(cogImage8Root); this.cogDisplayImage.Image = cogImage8Grey.ScaleImage((int)nWidth, (int)nHeight); System.GC.Collect(); } else { CogImage8Root image0 = new CogImage8Root(); IntPtr ptr0 = new IntPtr(pImageBuf.ToInt64()); image0.Initialize((int)nWidth, (int)nHeight, ptr0, (int)nWidth, null); CogImage8Root image1 = new CogImage8Root(); IntPtr ptr1 = new IntPtr(pImageBuf.ToInt64() + m_nRowStep); image1.Initialize((int)nWidth, (int)nHeight, ptr1, (int)nWidth, null); CogImage8Root image2 = new CogImage8Root(); IntPtr ptr2 = new IntPtr(pImageBuf.ToInt64() + m_nRowStep * 2); image2.Initialize((int)nWidth, (int)nHeight, ptr2, (int)nWidth, null); CogImage24PlanarColor colorImage = new CogImage24PlanarColor(); colorImage.SetRoots(image0, image1, image2); this.cogDisplayImage.Image = colorImage.ScaleImage((int)nWidth, (int)nHeight); System.GC.Collect(); } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); return; } return; }
public void SetDisplayImage(byte[] _DisplayImageArray, int _Width, int _Height) { try { var _Buffer = new SafeMalloc(_Width * _Height); Marshal.Copy(_DisplayImageArray, 0, _Buffer, _Width * _Height); var cogRoot = new CogImage8Root(); cogRoot.Initialize(_Width, _Height, _Buffer, _Width, _Buffer); var _CogImage = new CogImage8Grey(); _CogImage.SetRoot(cogRoot); //ICogImage InspectionImage = (ICogImage)_CogImage; SetDisplayInvoke(kCogDisplay, _CogImage); GC.Collect(); } catch { CLogManager.AddInspectionLog(CLogManager.LOG_TYPE.ERR, "SetDisplayImage(byte[]) Exception!!", CLogManager.LOG_LEVEL.LOW); } }