readimage类代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using HalconDotNet;
namespace readimage
{
class readimage
{
//定义全局变量
public HTuple Hwindows;//定义窗口句柄
HObject currentImg;//定义图像
HTuple imageWidth, imageHeight;//定义宽高
//定义加载图像函数
public void loadimg(HWindowControl HW,string Path)
{
//把当前控件绑定到Hwindows
Hwindows = HW.HalconWindow;
//读取图像
HOperatorSet.ReadImage(out currentImg, Path);
//自适应显示大小
HOperatorSet.GetImageSize(currentImg, out imageWidth, out imageHeight);
HOperatorSet.SetPart(Hwindows, 0, 0, imageHeight-1, imageWidth-1);
//显示图像
HOperatorSet.DispObj(currentImg, Hwindows);
}
}
}
大林上位机机器视觉_苏州电工培训_苏州PLC培训_苏州上位机培训_苏州机器视觉培训_苏州工业机器人培训_最适合电工及plc编程人员学习的上位机机器视觉课程 大林老师:15861139266(微信同号)
调用readimage类进行图像读取显示:
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 HalconDotNet;
namespace readimage
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
readimage read = new readimage();//对新建类实例化
private void button1_Click(object sender, EventArgs e)
{
using (OpenFileDialog ofg = new OpenFileDialog())
{
ofg.Filter = "图片|*.jpg;*.png;";//设置选取格式
ofg.Multiselect = false;//不支持多选
ofg.Title = "图片获取";
if (ofg.ShowDialog()==DialogResult.OK)
{
read.loadimg(hWindowControl1,ofg.FileName);
}
}
}
}
}
版权所有:江苏和讯自动化设备有限公司所有 备案号:苏ICP备2022010314号-1
技术支持: 易动力网络