HALCON 快速入门手册

 

 

  

 

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 HalconWindows{
public partial class Form1 : Form
{
HWindow win = null;//定义一个 Halcon 窗口对象
HImage image = null;//定义一个 Halcon 图像变量
public Form1()
{
//win = hWindowControl1.HalconWindow;这句放在 InitializeComponent()函
数前执行会报错
InitializeComponent();
win = hWindowControl1.HalconWindow;//将 Halcon 窗口对象与控件进行关
联
image = new HImage();//实例化图像变量
image.ReadImage(@"e:\rmb.png");//读取图像
int width = 0, height = 0;//创建变量用于接收图像尺寸
image.GetImageSize(out width, out height);//获取图像尺寸
win.SetPart(0, 0, height - 1, width - 1);//设置 Halcon 控件中图像的显示尺寸
win.DispObj(image);//显示图像
}
}
}

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
// halcon 命名空间
using HalconDotNet;
using namespace example
{
public partial class test Form
{
HDevelopExportModel HD = new HDevelopExportModel();
public Htuple hv_ExpDefaultWinHandleModel;
private void CreatModel(object sender, EventArgs e)
{
//这个是我在窗口上创建的一个 button,点击该 button 后,打开文件选择一
张图片,并将图片进行显示。
// 建立模板按钮
string ImagePath;      // 定义模板图片的路径
HObject readImage = null; // 定义一个图像常量
OpenFileDialog openFileDialog1 = new OpenFileDialog(); //打开文件进行选择
openFileDialog1.Filter = "BMP 文件|*.bmp*|PNG 文件|*.png*|JPEG 文件|*.jpg*";
//图片的文件格式
openFileDialog1.RestoreDirectory = true;
openFileDialog1.FilterIndex = 1;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
// 如果可以打开该文件路径,将该文件路径的图片显示在
hWindowControl2 窗口,并将图片变量赋值给 readImage
ImagePath = openFileDialog1.FileName;
readImage = HD.ReadPicture(hWindowControl2.HalconWindow,
ImagePath);

// 读取这张图片并将图片赋值给 readImage,这句就是直接调的 halcon
类了,下边public 定义的的是他的类
}
}
}
public partial class HDevelopExportModel
{
public HObject ReadPicture(HTuple window, string ImagePath)
{
// 得到图片显示的窗口句柄
hv_ExpDefaultWinHandleModel = window; //从上个函数传进来的窗口句柄
HOperatorSet.GenEmptyObj(out ho_Image);
ho_Image.Dispose();
HOperatorSet.ReadImage(out ho_Image, ImagePath); //从这个路径读取图片
HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height); //得到
他的大小
HOperatorSet.SetWindowAttr("background_color", "black");
//调整窗口显示大小以适应图片,这句一定要加上,不然图片显示的不全
HOperatorSet.SetPart(hv_ExpDefaultWinHandleModel, 0, 0, hv_Height - 1,
hv_Width - 1);
HOperatorSet.DispObj(ho_Image, hv_ExpDefaultWinHandleModel); //将图像
在该窗口进行显示
return ho_Image; //返回这个图像
}
} //end HDevelopExportModel
}// end example

  • 9
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值