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;
                }
            }
        }
       
  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值