示例#1
0
 private void picBox_Paint(object sender, PaintEventArgs e)
 {
     if (_imgShowMode == ImgShowMode.bitmap)
     {
         if (null != _currBmp)
         {
             e.Graphics.DrawImage(_currBmp, new Rectangle(0, 0, picBox.Width, picBox.Height));
             return;
         }
     }
     else if (_imgShowMode == ImgShowMode.halcon)
     {
         //hcWnd.CloseWindow();
         //hcWnd.OpenWindow(picBox.Location.X, picBox.Location.Y, picBox.Width, picBox.Height, picBox.Handle, "visible", "");
         //if(null != _currHo)
         //    HOperatorSet.DispObj(_currHo, hcWnd);
     }
     else if (_imgShowMode == ImgShowMode.sdk)
     {
         if (null != _currImage)
         {
             _currImage.DisplayTo(picBox.Handle);
         }
     }
 }
示例#2
0
        void ShowImg(IJFImage img)
        {
            if (InvokeRequired)
            {
                Invoke(new dgShowImg(ShowImg), new object[] { img });
                return;
            }
            int err = 0;

            if (_imgShowMode == ImgShowMode.sdk) // 使用SDK内部自带的图片显示功能
            {
                picWnd = picBox.Handle;
                err    = img.DisplayTo(picWnd);
                if (err != 0)
                {
                    if (!chkContinueGrab.Checked)
                    {
                        MessageBox.Show("SDK显示图像失败,错误信息:" + _currImage.GetErrorInfo(err) + " " + DateTime.Now.ToString("HH:mm:ss:ms"));
                    }
                    else
                    {
                        ShowTips("SDK显示图像失败,错误信息:" + _currImage.GetErrorInfo(err) + " " + DateTime.Now.ToString("HH:mm:ss:ms"));
                    }
                }
                else
                {
                    ShowTips("SDK显示图像完成");
                }
            }
            else if (_imgShowMode == ImgShowMode.halcon) //Halcon显示图片
            {
                if (_currHo != null)
                {
                    _currHo.Dispose();
                    _currHo = null;
                }
                object hoImage = null;
                ShowTips("Halcon转换开始:" + DateTime.Now.ToString("HH:mm:ss:ms"));
                err = img.GenHalcon(out hoImage);
                if (err != 0)
                {
                    ShowTips("显示图片失败,未能将图片转化为Halcon对象,错误信息:" + img.GetErrorInfo(err));
                    if (!chkContinueGrab.Checked)
                    {
                        MessageBox.Show("显示图片失败,未能将图片转化为Halcon对象,错误信息:" + img.GetErrorInfo(err));
                    }
                    return;
                }
                ShowTips("Halcon转换完成:" + DateTime.Now.ToString("HH:mm:ss:ms"));
                ShowHalconImg((HObject)hoImage, img.PicWidth, img.PicHeight);
                _currHo = (HObject)hoImage;
                ShowTips("图像显示完成:" + DateTime.Now.ToString("HH:mm:ss:ms"));
            }
            else if (_imgShowMode == ImgShowMode.bitmap) //
            {
                ShowTips("Bitmap转换开始:" + DateTime.Now.ToString("HH:mm:ss:ms"));
                Bitmap bmp = null;
                err = img.GenBmp(out bmp);
                if (err != 0)
                {
                    ShowTips("显示图片失败,未能将图片转化为Bitmap对象,错误信息:" + _currImage.GetErrorInfo(err));
                    if (!chkContinueGrab.Checked)
                    {
                        MessageBox.Show("显示图片失败,未能将图片转化为Bitmap对象,错误信息:" + _currImage.GetErrorInfo(err));
                    }
                    return;
                }
                ShowTips("Bitmap转换完成:" + DateTime.Now.ToString("HH:mm:ss:ms"));
                ShowBitmap(bmp);////
                if (null != _currBmp)
                {
                    _currBmp.Dispose();
                    _currBmp = bmp;
                }
            }
            _currImage = img;
        }