Exemplo n.º 1
0
            public static MvSCodeContent GetInstance()
            {
                MvSCodeContent param = new MvSCodeContent();

                param.content = new byte[MVConst.Len_100];
                return(param);
            }
Exemplo n.º 2
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);
        }