Demo目的,图像同步到附属窗口,通过附属窗口各类操作(参数设置,ROI重置等)简化主界面
本文主要演示图像传递
主界面
附属界面
运行效果
主界面代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ViewControl;
using HalconDotNet;
using System.Reflection.Emit;
using static System.Net.Mime.MediaTypeNames;
namespace DeepLearningTest1
{
public partial class FormMain : Form
{
HalconView HW;
HObject HIMage = new HObject();
public FormMain()
{
InitializeComponent();
HW = new HalconView();
HW.HWindowControl.BackColor = Color.White;
splitContainer1.Panel1.Controls.Add(HW);
HW.Dock = DockStyle.Fill;
}
/// <summary>
/// 加载图像
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, EventArgs e)
{
try
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "图片文件(*.bmp;*.jpg;*.gif;*.png;*.tiff;*.tif)|*.bmp;*.jpg;*.gif;*.png;*.tiff;*.tif";
openFileDialog.RestoreDirectory = true;
openFileDialog.FilterIndex = 1;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
label3.Text = openFileDialog.FileName;
HOperatorSet.ReadImage(out HIMage, label3.Text);
HW.DispImage(HIMage, true);
}
}
catch (Exception ex)
{
MessageBox.Show("加载图片失败 " + ex.ToString());
}
}
private void btn_DrawROI_Click(object sender, EventArgs e)
{
Form2 F2 = new Form2( HIMage);
F2.Show();
}
}
}
附属界面
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ViewControl;
using HalconDotNet;
using static System.Net.Mime.MediaTypeNames;
namespace DeepLearningTest1
{
public partial class Form2 : Form
{
//声明变量
HalconView HW2;
HObject HIMage2 = new HObject();
public Form2(HObject HIMage)
{
InitializeComponent();
//赋值
HIMage2 = HIMage;
//初始化窗口
HW2 = new HalconView();
HW2.HWindowControl.BackColor = Color.White;
splitContainer1.Panel2.Controls.Add(HW2);
HW2.Dock = DockStyle.Fill;
}
/// <summary>
/// 加载图像
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btn_loadImage_Click(object sender, EventArgs e)
{
if (!HIMage2.IsInitialized()) { MessageBox.Show("图片为空"); return; }
HW2.DispImage(HIMage2, true);
}
private void btn_save_Click(object sender, EventArgs e)
{
}
}
}