Home > Net >  C # image interaction with multithreading
C # image interaction with multithreading

Time:09-28

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. The Threading;

The namespace Demo
{
Public partial class Form1: Form
{
Private HTuple WindowID;
Private HObject image;

Private HObject [] ImageArry=new HObject [7].//store image array

//thread object
Private Thread ThreadObject;//normal test thread

//control thread state
Private bool Thread_Stop=false;//normal test thread a stop sign

Public _click ()
{
InitializeComponent ();
Image=new HObject ();

CreateWindow ();
//Loadimage ();
LoadBatchImage ();

ThreadObject=new Thread (new ThreadStart (playthread));
}

//thread function
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 & gt;=7)
{
i=0;
}
}
}

//bulk loading images
Public void LoadBatchImage ()
{
for (int i=0; i <7. I++)
{
HOperatorSet. ReadImage (out ImageArry [I], i.T oString () + ". PNG ");
}
}

Public void CreateWindow ()
{
HTuple FatherWidnow=this. PictureBox. Handle;

HOperatorSet. SetWindowAttr (" background_color ", "green");
HOperatorSet. OpenWindow (0, 0, this. PictureBox. Width, enclosing pictureBox. Height, FatherWidnow, "visible", "", the 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. The Threading. ThreadState. Unstarted)
{
ThreadObject. Start ();
}

If (ThreadObject. ThreadState==System. The 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 the local and the output iconic variables
HOperatorSet. GenEmptyObj (out ho_Image);
HOperatorSet. GenEmptyObj (out ho_Circle);


HOperatorSet. SetColor (WindowID, "yellow");

HOperatorSet. SetDraw (WindowID, "margin");



HOperatorSet. Methods like DrawCircle (WindowID out hv_Row, out hv_Column, out hv_Radius);

Ho_Circle. The Dispose ();
HOperatorSet. GenCircle (out ho_Circle hv_Row, hv_Column, hv_Radius);

HOperatorSet. DispObj (ho_Circle WindowID);

Ho_Image. The Dispose ();
Ho_Circle. The Dispose ();
}

Private void Exit_Click (object sender, EventArgs e)
{
Thread_Stop=true;
Enclosing the Close ();
}
}
}

CodePudding user response:

So... ?

CodePudding user response:

Comment is too little, bad review,
  •  Tags:  
  • C#
  • Related