Пример #1
0
        public System.Drawing.Bitmap GetBitmap()
        {
            MvsCommon.MvSImage imageinfo =
                (MvsCommon.MvSImage)Marshal.PtrToStructure(_omResult.pSheetImg, typeof(MvsCommon.MvSImage));

            int width = imageinfo.Width, height = imageinfo.Height;

            var    fmt       = PixelFormat.Format8bppIndexed;
            Bitmap returnBmp = new Bitmap(width, height, fmt);
            var    palette   = returnBmp.Palette;

            for (var ii = 0; ii < 256; ii++)
            {
                palette.Entries[ii] = Color.FromArgb(ii, ii, ii);
            }
            returnBmp.Palette = palette;

            // 使用ptr指针指向的数据构造位图
            var d = returnBmp.LockBits(new Rectangle(0, 0, width, height),
                                       ImageLockMode.WriteOnly | ImageLockMode.UserInputBuffer, fmt,
                                       new BitmapData
            {
                PixelFormat = fmt,
                Height      = height,
                Width       = width,
                Stride      = width,
                Scan0       = imageinfo.ImageData
            });

            returnBmp.UnlockBits(d);


            return(returnBmp);
        }
Пример #2
0
        /// <summary>
        /// 主处理函数
        /// </summary>
        /// <param name="bmp">传入图片</param>
        /// <param name="mcList">条码信息</param>
        /// <returns>传出图片</returns>
        public void MattingProcess(System.Drawing.Bitmap bmp, List <MvBarCode.MvCodeInfo> mcList)
        {
            MvSMattingProcessParam omParam = MvSMattingProcessParam.GetInstance();

            _omResult = MvSMattingProcessResult.GetInstance();

            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

            System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);

            var ptrImage = bmpData.Scan0;

            MvsCommon.MvSImage img = MvsCommon.MvSImage.GetInstance();
            img.Height    = bmp.Height;
            img.Width     = bmp.Width;
            img.ImageData = ptrImage;
            img.DataType  = Convert.ToInt32(MvsImgDataType.MVS_IMGDTP_U8);
            img.Type      = Convert.ToInt32(MvsImgType.MVS_IMGTP_UITL_Y);

            omParam.pSrcImg = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvsCommon.MvSImage)));
            Marshal.StructureToPtr(img, omParam.pSrcImg, false);

            var ptrPoint = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvsCommon.MvSPoint)) * 12);

            for (int j = 0; j < mcList.Count; j++)
            {
                for (int i = 0; i < mcList[j].Region.PtArray.Length; i++)
                {
                    MvsCommon.MvSPoint pt;

                    pt.x = mcList[j].Region.PtArray[i].X;
                    pt.y = mcList[j].Region.PtArray[i].Y;

                    Marshal.StructureToPtr(pt, ptrPoint + Marshal.SizeOf(typeof(MvsCommon.MvSPoint)) * i, false);
                }
            }

            omParam.pCodePos = ptrPoint;
            omParam.nCode    = 1;


            MVAPI.mattingProcess(m_handle, ref omParam, ref _omResult);


            bmp.UnlockBits(bmpData);
        }
Пример #3
0
 /// <summary>
 /// 构造函数
 /// </summary>
 public MvsImageParam()
 {
     _Param = MvsCommon.MvSImage.GetInstance();
 }
Пример #4
0
        /// <summary>
        /// 主处理函数
        /// </summary>
        /// <param name="bmp">传入图片</param>
        /// <param name="mcList">条码信息</param>
        /// <returns>传出图片</returns>
        public int Process(Bitmap bmp, string code, List <MvBarCode.MvCodeInfo> mcList, int flag)
        {
            MvSSharpnessMeasureProcessParam  processParam  = MvSSharpnessMeasureProcessParam.GetInstance();
            MvSSharpnessMeasureProcessResult processResult = MvSSharpnessMeasureProcessResult.GetInstance();

            Rectangle rect = new Rectangle(0, 0, bmp.Width, bmp.Height);

            System.Drawing.Imaging.BitmapData bmpData = bmp.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, bmp.PixelFormat);

            var ptrImage = bmpData.Scan0;

            MvsCommon.MvSImage img = MvsCommon.MvSImage.GetInstance();
            img.Height    = bmpData.Height;
            img.Width     = bmpData.Width;
            img.ImageData = ptrImage;
            img.DataType  = Convert.ToInt32(MvsImgDataType.MVS_IMGDTP_U8);
            img.Type      = Convert.ToInt32(MvsImgType.MVS_IMGTP_UITL_Y);

            processParam.pSrcImg = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvsCommon.MvSImage)));
            Marshal.StructureToPtr(img, processParam.pSrcImg, false);

            processParam.nRegion  = 1;
            processParam.bCmpFlag = flag;



            var    ptrPoint   = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvsCommon.MvSPoint)) * 12);
            IntPtr ptrContent = IntPtr.Zero;

            ptrContent = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(MvSCodeContent)) * 10);
            for (int j = 0; j < mcList.Count; j++)
            {
                for (int i = 0; i < mcList[j].Region.PtArray.Length; i++)
                {
                    MvsCommon.MvSPoint pt;

                    pt.x = mcList[j].Region.PtArray[i].X;
                    pt.y = mcList[j].Region.PtArray[i].Y;

                    Marshal.StructureToPtr(pt, ptrPoint + Marshal.SizeOf(typeof(MvsCommon.MvSPoint)) * i, false);
                }

                MvSCodeContent codeContent = MvSCodeContent.GetInstance();
                Array.Copy(Encoding.Default.GetBytes(mcList[j].Code), codeContent.content, mcList[j].CodeLen);
                //codeContent.content = Encoding.Default.GetBytes(mcList[j].Code);
                codeContent.len = mcList[j].CodeLen;

                Marshal.StructureToPtr(codeContent, ptrContent + Marshal.SizeOf(typeof(MvSCodeContent)) * j, false);
                //Marshal.StructureToPtr(codeContent, ptrContent, false);
            }

            processParam.Pts = ptrPoint;

            processParam.CodeContent = ptrContent;

            try
            {
                int result = MVSHARP.sharpnessMeasureProcess(m_handle, ref processParam, ref processResult);
            }



            catch (Exception ex)
            {
                MvBarCodeGlobalVar.Log.Error(ex);
            }

            bmp.UnlockBits(bmpData);

            return(processResult.score);
        }