C# Halcon 图像放大缩小代码

8 篇文章 0 订阅

 

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)
                        {
                        }
                    }

                }

            }
        }

 

  • 5
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值