如何使用LEADTOOLS图像标注控件在界面上对图像进行标注

发布时间:2017/09/22 00:09 发布者:Richard.Ma

返回博客中心

leadtools对图像和文档提供了多种类型的标注,允许用户通过图形界面或者后台代码进行插入。本教程将按照步骤分享如何使用图像标注控件在界面上对图像进行标注。

1.创建VS项目

在VS中创建winform项目,创建完成后需要确认使用的.NET版本以及编译的目标平台。本例采用.NET4.0和X86平台进行编译。

 

2.引用接口dll

需要引用的dll列表如下,可以在C:\LEADTOOLS 19\Bin\Dotnet4\Win32找到。

image

主界面Form1代码中添加引用

using System.Windows.Forms;
using Leadtools;
using Leadtools.Codecs;
using Leadtools.WinForms;
using Leadtools.Annotations;

 

3.主界面添加相关控件

在设计界面添加一个MenuStrip菜单

添加按钮用以打开文件;

添加下拉框,包括2个选项:标注模式和浏览模式

 

4.后台代码编写

4.1控件初始化相关代码

添加相关对象

        RasterImageViewer viewer = new RasterImageViewer();
        RasterImage img;
        AnnAutomationManager annger;
        AnnAutomation automation;

添加initControl()方法,用于初始化图片浏览控件以及标注相关控件,在Form1()构造函数中调用该方法

private void initControl() {
            Support.SetLicense();
            viewer.Dock = DockStyle.Fill;
            panel1.Controls.Add(viewer);
            viewer.HorizontalAlignMode = RasterPaintAlignMode.Center;
            viewer.VerticalAlignMode = RasterPaintAlignMode.Center;
            loadImage("qwe.jpg");
            if (viewer.Image != null)
            {
                // create and setup the automation manager 
                annger = new AnnAutomationManager();

                // Instruct the manager to create the default (all) automation objects. 
                annger.CreateDefaultObjects();

                // create the toolbar and add it to the form 
                annger.CreateToolBar();
                Controls.Add(annger.ToolBar);

                // setup the automation (will create the container as well) 
                automation = new AnnAutomation(annger, viewer);

                // add an event handler for changes to the current designer 
                automation.CurrentDesignerChanged += new EventHandler(automation_CurrentDesignerChanged);

                // setup this automation as the active one 
                automation.Active = true;
            }
            toolStripComboBox1.SelectedIndex = 0;
        }

 

4.2添加加载图像方法

private void loadImage(string filename)
        {
            img = new RasterCodecs().Load(filename);
            viewer.Image = img;
        }

 

4.3添加automation_CurrentDesignerChanged方法

private void automation_CurrentDesignerChanged(object sender, EventArgs e)
        {
            AnnAutomation automation = sender as AnnAutomation;
            AnnButtonRunDesigner buttonRunDesigner = automation.CurrentDesigner as AnnButtonRunDesigner;
            if (buttonRunDesigner != null)
                buttonRunDesigner.Run += new EventHandler<AnnRunDesignerEventArgs>(buttonRunDesigner_Run);
        }

 

4.4添加buttonRunDesigner_Run方法

private void buttonRunDesigner_Run(object sender, AnnRunDesignerEventArgs e)
        {
            if (e.OperationStatus == AnnDesignerOperationStatus.End)
            {
                AnnButtonObject btn = e.Object as AnnButtonObject;
                MessageBox.Show(string.Format("Button with text = {0} was clicked!", btn.Text));
            }
        }

 

4.5添加打开文件按钮事件方法

private void loadImage(string filename)
        {
            img = new RasterCodecs().Load(filename);
            viewer.Image = img;
        }

 

4.6添加模式下拉框选项改变事件方法

private void toolStripComboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            annger.UserMode = (toolStripComboBox1.SelectedIndex == 0) ? AnnUserMode.Design : AnnUserMode.Run;
        }

 

5.编译运行

演示程序界面如下图所示

image

 

下载示例代码

点击下面的链接下载

转载声明:
欢迎将本站文章进行转载、演绎或用于商业目的,转载时请注明以下信息
文章转自:葡萄城技术博客,http://blog.gcpowertools.com.cn
原文地址:http://blog.gcpowertools.com.cn/post/annotation_startup.aspx

不允许评论

关于葡萄城

赋能开发者!葡萄城是专业的集开发工具、商业智能解决方案、低代码开发平台于一身的软件和服务提供商,为超过 75% 的全球财富 500 强企业提供服务。葡萄城专注控件软件领域30年,希望通过模块化的开发控件、灵活的低代码应用开发平台等一系列开发工具、解决方案和服务,帮助开发者快速响应复杂多变的业务需求,最大程度地发挥开发者的才智和潜能,让开发者的 IT 人生更从容更美好。

了解详情,请访问葡萄城官网