Solved

Trigger Pixel Change on Screen and do something

Posted on 2009-04-06
1
291 Views
Last Modified: 2013-12-17
Hi @ all

GetColor allows me to retrieve the color of any pixel on the screen

Now i attempt to solve out how to trigger an action whenever the pixel color of X,Y-coordinates anywhere on screen changes. This should stop the methode RunApp() and start again.

Thanks in advance!
public Color GetColor(int x, int y)
{
	Bitmap b = new Bitmap(1, 1);
	Graphics g = Graphics.FromImage(b);
	g.CopyFromScreen(x, y, 0, 0, b.Size);
	g.Dispose();
	Color c = b.GetPixel(0, 0);
	b.Dispose();
 
	return c;
}
public void RunApp()
{	
	if (comboBoxPlatzAmTisch.Text == "")
	{
			MessageBox.Show("Geben Sie Ihren Platz am Tisch an!");
	}
	else
	{
		Color sResult = GetColor(iKartenPositionen[i, 0], iKartenPositionen[i, 1]);
		sResult = KarteVorhanden();
		if (sResult == true)	
		{
			ScreenshotSpieler(iSpielerPlatz);			
			bool fAktiv = GetPixelColor();
			if (fAktiv == true){
				//here follows more nested if statements}
		}
		else
		{
			Pockal.Clear();
			Tisch.Clear();
			Gegner.SelectedIndex = 0;
		}
	}	
}

Open in new window

0
Comment
Question by:pekabo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
pekabo earned 0 total points
ID: 24106342
Unfortunately, no answer.
A solution for my problem could looks like this (it works for me)

i use backgroundWorker (DoWork, RunWorkerCompleted, ProgressChanged)
i made a do while loop if the color of the pixel like the color in Color it returns a true
this will stop the Loop. Now i can ask is backgroundPL1.IsBusy = true, NO Pixel Changed
if backgroundPL1.IsBusy = false the color of the pixel Cahnged

see Code Snippet below.

p.s.: please refund the points, i wont´t delete this message, because other could maybe learn from it
private void backgroundPL1_DoWork(object sender, DoWorkEventArgs e, Color ColorName)
{
int i = 1;
 
	if ((workerPL8.CancellationPending == true))
	{		
		return;
	}
	else
	{
		bool a = false;
		do
		{
			Bitmap b = new Bitmap(1, 1);
			Graphics g = Graphics.FromImage(b);
			g.CopyFromScreen(x, y, 0, 0, b.Size);
			g.Dispose();
			Color c = b.GetPixel(0, 0);
			b.Dispose();
			if (c.Name != ColorName) a = true;
			if (i > 100) i = 1;
			
			workerPL8.ReportProgress(i);			
					
			Thread.Sleep(1);
			//Keep UI messages moving, so the form remains 
                        //responsive during the asynchronous operation.	
			Application.DoEvents();
			
			i++;
		} while (a == false);
	}
}

Open in new window

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question