visionpro 图片格式转海康图片格式

记录一下图片格式转换 CogImage8Grey 转CMvdImage,ICogImage转CMvdImage同理

        //图像转换工具
        public class ImageConvetor 
        {
            public CMvdImage toMvdImage(CogImage8Grey cogImage)
            {
                try
                {
                    ICogImage8Root cogImage8Root;
                    ICogImage8PixelMemory cogImage8PixelMemory;
                    cogImage.GetRoot(out cogImage8Root);
                    cogImage8Root.GetRawPixelMemory(CogImageDataModeConstants.Read, 0, 0, cogImage.Width, cogImage.Height, out cogImage8PixelMemory);

                    int width = cogImage.Width;
                    int height = cogImage.Height;
                    byte[] SrcData = new byte[height * width];//图像数据
                    Marshal.Copy(cogImage8PixelMemory.Scan0, SrcData, 0, (int)SrcData.Length);
                    CMvdImage tempImage = new CMvdImage();
                    VisionDesigner.MVD_IMAGE_DATA_INFO stData = new MVD_IMAGE_DATA_INFO();
                    stData.stDataChannel[0].arrDataBytes = SrcData;
                    stData.stDataChannel[0].nLen = (uint)SrcData.Length;
                    stData.stDataChannel[0].nRowStep = (uint)width;
                    stData.stDataChannel[0].nSize = (uint)(height * width);
                    tempImage.InitImage((uint)width, (uint)height, VisionDesigner.MVD_PIXEL_FORMAT.MVD_PIXEL_MONO_08, stData);
                    return tempImage;
                }
                catch (Exception ex)
                {
                    return null;
                }
            }
        }
       
上一篇:big.Int阶乘


下一篇:基于单片机控制双向可控硅灯光强度设计-全套资料