C# Halcon 图像放大缩小代码

 

private void hWindowControl1_HMouseWheel(object sender, HalconDotNet.HMouseEventArgs e)
        {
            if (ho_img != null)
            {
                try
                {
                    //获取鼠标位置
                    hwin1.GetMpositionSubPix(out mposition_row, out mposition_col, out button_state);
                    //获取显示控件像素位置
                    hwin1.GetPart(out current_beginRow1, out current_beginCol1, out current_endRow1, out current_endCol1);
                    //获取显示像素大小
                    Ht = current_endRow1 - current_beginRow1;
                    Wt = current_endCol1 - current_beginCol1;
                }
                catch (HalconException)
                {
                }
                if (e.Delta > 0)                 // 放大图像
                {
                    if (Ht > 4)
                    {
                        zoom_beginRow1 = (int)(current_beginRow1 + (mposition_row - current_beginRow1) * 0.300d);
                        zoom_beginCol1 = (int)(current_beginCol1 + (mposition_col - current_beginCol1) * 0.300d);
                        zoom_endRow1 = (int)(current_endRow1 - (current_endRow1 - mposition_row) * 0.300d);
                        zoom_endCol1 = (int)(current_endCol1 - (current_endCol1 - mposition_col) * 0.300d);
                        hwin1.SetPart(zoom_beginRow1, zoom_beginCol1, zoom_endRow1, zoom_endCol1);
                        hwin1.ClearWindow();
                        try
                        {
                            HSystem.SetSystem("flush_graphic", "true");
                            if (cbxImage.Text != ""&& Image.Count>0)
                               DispImage(Image[cbxImage.Text], true);
                            else
                                hwin1.DispObj(ho_img);
                            OnHMouseWheelEvent();
                            if (中心ToolStripMenuItem.Checked)
                                disp_win_cross(ho_img);
                            HSystem.SetSystem("flush_graphic", "false");
                        }
                        catch (HalconException)
                        {
                        }
                    }
                }

                else                           // 缩小图像
                {

                    if (Ht < 8000)
                    {
                        zoom_beginRow1 = (int)(mposition_row - (mposition_row - current_beginRow1) / 0.700d);
                        zoom_beginCol1 = (int)(mposition_col - (mposition_col - current_beginCol1) / 0.700d);
                        zoom_endRow1 = (int)(mposition_row + (current_endRow1 - mposition_row) / 0.700d);
                        zoom_endCol1 = (int)(mposition_col + (current_endCol1 - mposition_col) / 0.700d);
                        hwin1.SetPart(zoom_beginRow1, zoom_beginCol1, zoom_endRow1, zoom_endCol1);
                        hwin1.ClearWindow();
                        try
                        {
                            HSystem.SetSystem("flush_graphic", "true");
                            hwin1.DispObj(ho_img);
                            if (中心ToolStripMenuItem.Checked)
                                disp_win_cross(ho_img);
                            HSystem.SetSystem("flush_graphic", "false");
                           OnHMouseWheelEvent();
                        }
                        catch (HalconException)
                        {
                        }
                    }

                }

            }
        }

 

你可能感兴趣的:(C#,Halcon)