943,165 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 4568
  • C# RSS
Feb 1st, 2010
0

Get coordinates of pixel color

Expand Post »
Hi,

I was wondering how I can get the coordinates of a specific color from a window? Is it possible.

I did some research, but I only found to get a color from coordinates, but I need it the other way around.

Atm I have this, I don't know if it is right, cause I usually program in java.

C# Syntax (Toggle Plain Text)
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Runtime.InteropServices;
  6.  
  7. namespace ConsoleApplication2
  8. {
  9. class Program
  10. {
  11.  
  12. [DllImport("user32.dll", CharSet = CharSet.Auto)]
  13. public static extern IntPtr FindWindow(string lpClassName, string lpWindowName);
  14.  
  15. [DllImport("user32.dll", EntryPoint = "GetDC")]
  16. public static extern IntPtr GetDC(IntPtr ptr);
  17.  
  18. static void Main(string[] args)
  19. {
  20.  
  21. IntPtr nWnd = FindWindow("","DutchLeader - Uitnodigingen - Windows Internet Explorer");
  22. if (nWnd != IntPtr.Zero)
  23. {
  24. IntPtr dcWindow = GetDC(nWnd);
  25. //Here should come the code to get the coordinates from the color pixel
  26. }
  27. else
  28. {
  29. Console.WriteLine("Window niet gevonden");
  30. }
  31. }
  32. }
  33. }

The second problem is that he can't findow the window. The window he needs to get, can be seen in photo which is in attachment.

Grtz
Attached Thumbnails
Click image for larger version

Name:	Troubles.jpg
Views:	116
Size:	14.4 KB
ID:	13482  
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
Kligham is offline Offline
36 posts
since Jun 2009
Feb 1st, 2010
0
Re: Get coordinates of pixel color
>how I can get the coordinates of a specific color from a window?

Take a look at codeproject article - http://www.codeproject.com/KB/miscctrl/ColorGET.aspx
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,525 posts
since Oct 2008
Reputation Points: 8
Solved Threads: 7
Light Poster
pauldani is offline Offline
49 posts
since Jan 2010
Feb 2nd, 2010
0
Re: Get coordinates of pixel color
I think you probably misunderstood me. What I need is when I define the RGB values, the program should look for them and give me the coordinates of where it is found. Me/The program doesn't know a coordinate, it needs to search for it.

For example:

Red: 85
Green: 23
Blue: 240

Then program needs to search of the window (like in code)
Last edited by Kligham; Feb 2nd, 2010 at 8:26 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
Kligham is offline Offline
36 posts
since Jun 2009
Feb 2nd, 2010
0
Re: Get coordinates of pixel color
A BitMap has a GetPixel method which returns a Color struct for the Color at coordinates X Y in the Bitmap. A Color struct can Compare one Color with another. So loop through every pixel of your bitmap and test for your color. If found you got your desired position.
Reputation Points: 2023
Solved Threads: 643
Senior Poster
ddanbe is offline Offline
3,733 posts
since Oct 2008
Feb 2nd, 2010
0
Re: Get coordinates of pixel color
There is a problem with this, very seldom will there be only 1 pixel of a particular color anywhere, It is very l likely that you will get hundreds of coordinates with even an unpopular color as many images contain millions of colors to make up and image.

but I digress a good approach would be to capture the entire screen as a bitmap (assuming you want screen coordinates) and then loop through that bitmap using getpixel and compare its color to your color, and then add that coordinate to your List of coordinates.

if you just wanted to look in a particular window, you can still screen cap the whole screen but just loop through a rectangle that is bound to that windows position on screen.


although, I can't see the use for this. Best of luck.
Last edited by Diamonddrake; Feb 2nd, 2010 at 4:25 pm.
Reputation Points: 442
Solved Threads: 89
Master Poster
Diamonddrake is offline Offline
721 posts
since Mar 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: How a tick remains in a listView
Next Thread in C# Forum Timeline: C# problem





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC