halcon联合C#做采集,用定时器,遇到了不明窗口挡在前面,到底是个啥啊。。
该窗口会闪烁
**以下是实现代码
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 助手联合相机
{
public partial class Form1 : Form
{
//1、定义变量
HObject ho_Image = null;
HTuple hv_AcqHandle = new HTuple(), hv_Width = new HTuple();
HTuple hv_Height = new HTuple(), hv_MSecond = new HTuple();
HTuple hv_Second = new HTuple(), hv_Minute = new HTuple();
HTuple hv_Hour = new HTuple(), hv_Day = new HTuple(), hv_YDay = new HTuple();
HTuple hv_Month = new HTuple(), hv_Year = new HTuple();
HTuple hv_WindowHandle = null;//窗口句柄
private void timer1_Tick(object sender, EventArgs e)
{
//3、打开相机
ho_Image.Dispose();
HOperatorSet.GrabImageAsync(out ho_Image, hv_AcqHandle, -1);
hv_Width.Dispose(); hv_Height.Dispose();
HOperatorSet.GetImageSize(ho_Image, out hv_Width, out hv_Height);
if (HDevWindowStack.IsOpen())
{
//图片显示完整,把第一个变量的句柄改一下
HOperatorSet.SetPart(hWindowControl2.HalconWindow, 0, 0, hv_Height - 1, hv_Width - 1);
}
if (HDevWindowStack.IsOpen())
{
HOperatorSet.DispObj(ho_Image, hWindowControl2.HalconWindow);
}
}
public Form1()
{
InitializeComponent();
}
private void OpenCamera_CheckedChanged(object sender, EventArgs e)
{
//2、初始化相机
HOperatorSet.GenEmptyObj(out ho_Image);
hv_AcqHandle.Dispose();
HOperatorSet.OpenFramegrabber("GigEVision2", 0, 0, 0, 0, 0, 0, "progressive",
-1, "default", -1, "false", "default", "SJH00", 0, -1, out hv_AcqHandle);
HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "ExposureTime", 15020.0); //设置曝光
HOperatorSet.SetFramegrabberParam(hv_AcqHandle, "Gain", 3.9849); //设置增益
HOperatorSet.GrabImageStart(hv_AcqHandle, -1);
timer1.Enabled = true;
//输入控件的宽和高,控件的句柄
HOperatorSet.OpenWindow(0, 0, hWindowControl2.Height, hWindowControl2.Width, hWindowControl2.HalconWindow, "visible", "", out hv_WindowHandle);
HDevWindowStack.Push(hv_WindowHandle);
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
求助大佬们,halcon图像采集有问题。。!
最新推荐文章于 2024-08-26 00:19:47 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)