基本信息
源码名称:C#图像交互与多线程
源码大小:26.92M
文件格式:.zip
开发语言:C#
更新时间:2019-03-28
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
初学c#与halcon联合编程的人比较实用
初学c#与halcon联合编程的人比较实用
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 HalconDotNet; using System.Threading; namespace Demo { public partial class Form1 : Form { private HTuple WindowID; private HObject image; private HObject[] ImageArry = new HObject[7]; //存放图像的数组 //线程对象 private Thread ThreadObject; //正常测试线程 //控制线程的状态 private bool Thread_Stop = false; //正常测试线程停止标志 public Form1() { InitializeComponent(); image = new HObject(); CreateWindow(); //Loadimage(); LoadBatchImage(); ThreadObject = new Thread(new ThreadStart(playthread)); } //线程函数 public void playthread() { int i = 0; Thread_Stop = false; HTuple width = null; HTuple height = null; while (!Thread_Stop) { HOperatorSet.DispObj(ImageArry[i], WindowID); HOperatorSet.GetImageSize(ImageArry[i], out width, out height); HOperatorSet.SetPart(WindowID, 0, 0, height, width); Thread.Sleep(100); i ; if (i >= 7) { i = 0; } } } //批量加载图像 public void LoadBatchImage() { for (int i = 0; i < 7; i ) { HOperatorSet.ReadImage(out ImageArry[i], i.ToString() ".png"); } } public void CreateWindow() { HTuple FatherWidnow = this.pictureBox.Handle; HOperatorSet.SetWindowAttr("background_color", "green"); HOperatorSet.OpenWindow(0, 0, this.pictureBox.Width, this.pictureBox.Height, FatherWidnow, "visible", "", out WindowID); } public void Loadimage() { HOperatorSet.ReadImage(out image, "1.png"); HTuple width = null; HTuple height = null; HOperatorSet.GetImageSize(image, out width, out height); HOperatorSet.SetColor(WindowID, "yellow"); HOperatorSet.SetPart(WindowID, 0, 0, height, width); HOperatorSet.DispObj(image, WindowID); } private void Begin_Click(object sender, EventArgs e) { Loadimage(); } private void Running_Click(object sender, EventArgs e) { if (ThreadObject.ThreadState == System.Threading.ThreadState.Unstarted) { ThreadObject.Start(); } if (ThreadObject.ThreadState == System.Threading.ThreadState.Stopped || ThreadObject.ThreadState == System.Threading.ThreadState.Aborted) { ThreadObject = new Thread(new ThreadStart(playthread)); ThreadObject.Start(); } } private void Stopping_Click(object sender, EventArgs e) { Thread_Stop = true; } private void DrawCircle_Click(object sender, EventArgs e) { HObject ho_Image, ho_Circle; // Local control variables HTuple hv_Row = null, hv_Column = null, hv_Radius = null; // Initialize local and output iconic variables HOperatorSet.GenEmptyObj(out ho_Image); HOperatorSet.GenEmptyObj(out ho_Circle); HOperatorSet.SetColor(WindowID, "yellow"); HOperatorSet.SetDraw(WindowID, "margin"); HOperatorSet.DrawCircle(WindowID, out hv_Row, out hv_Column, out hv_Radius); ho_Circle.Dispose(); HOperatorSet.GenCircle(out ho_Circle, hv_Row, hv_Column, hv_Radius); HOperatorSet.DispObj(ho_Circle, WindowID); ho_Image.Dispose(); ho_Circle.Dispose(); } private void Exit_Click(object sender, EventArgs e) { Thread_Stop = true; this.Close(); } } }