[HELP-CODE]Scanning Screen for pixel color

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2009
Posts: 37
Reputation: evilguyme is an unknown quantity at this point 
Solved Threads: 0
evilguyme evilguyme is offline Offline
Light Poster

[HELP-CODE]Scanning Screen for pixel color

 
0
  #1
Sep 27th, 2009
so far i have this code..

  1. #include "stdafx.h"
  2. #include <iostream>
  3. #include <windows.h>
  4. #include <string>
  5.  
  6.  
  7. using namespace std;
  8.  
  9. int main ()
  10. {
  11. const int r1 = 175;
  12. const int g1 = 163;
  13. const int b1 = 134;
  14.  
  15. HWND hwnd = FindWindow(NULL,"Test - Microsoft Visual Studio");
  16. SetForegroundWindow(hwnd);
  17. HDC hdc = GetDC(hwnd);
  18.  
  19. POINT lame;
  20. lame.x = 0;
  21. lame.y = 0;
  22.  
  23. int x = lame.x;
  24. int y = lame.y;
  25.  
  26.  
  27. for (int i = 0; i < 1280; i++)
  28. {
  29. x = i;
  30. y = 0;
  31.  
  32. COLORREF col = GetPixel(hdc,lame.x,lame.y);
  33.  
  34. int red1 = GetRValue(col);
  35. int green1 = GetGValue(col);
  36. int blue1 = GetBValue(col);
  37.  
  38.  
  39.  
  40. if (x == 1280)
  41. {
  42. y = lame.y++;
  43. i = 0;
  44. }
  45.  
  46. if (y == 801)
  47. {
  48. system("pause");
  49. }
  50.  
  51. if (red1 == r1 && green1 == g1 && blue1 == b1)
  52. {
  53. cout << "Pixel found at: \t" << "X: "<< x << "\t\t" << "Y: " << y << "\n";
  54. system("pause");
  55. }
  56. }
  57. system("pause");
  58. return 0;
  59.  
  60.  
  61.  
  62. }

i use it for scanning for a certain pixel on the screen but it doesn't seem to be working... no compiler or runtime errors but it just skips straight to press any key to continue...

i also can't find any resources to teach me some bitmap way..
if someone would care to explain how to capture screen to bmp and then analyze it for pixels..

or just tell me where i've gone wrong in my code.
[IMG]http://i621.photobucket.com/albums/tt298/evilguyme/StickMovie.gif[/IMG]
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,400
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 113
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

Re: [HELP-CODE]Scanning Screen for pixel color

 
0
  #2
Sep 27th, 2009
This code is confusing, that's your main problem. I don't understand the need for POINT lame; Also, line 40 is useless as i will never be equal to 1280 (only ever < than 1280).

If you want to loop through every pixel from point (0,0) and (1280,801) to find a pixel, do this:
  1. /* Untested code */
  2. COLORREF tofind = RGB(175, 163, 134);
  3. COLORREF col;
  4.  
  5. for (int y = 0; y < 801; ++y) {
  6. for (int x = 0; x < 1280; ++x) {
  7. col = GetPixel( hdc, x, y );
  8. if ( col == tofind ) {
  9. cout << "Pixel found at: \t" << "X: "<< x << "\t\t" << "Y: " << y << "\n";
  10. cin.ignore();
  11. }
  12. }
  13. }
  14.  
  15. cin.ignore();
Hope this helps.
Last edited by William Hemsworth; Sep 27th, 2009 at 10:38 am.
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 37
Reputation: evilguyme is an unknown quantity at this point 
Solved Threads: 0
evilguyme evilguyme is offline Offline
Light Poster

Re: [HELP-CODE]Scanning Screen for pixel color

 
0
  #3
Sep 27th, 2009
lemme try that. thnx for the code


that still doesn't work...

still exits program at the end.

so i added

  1. system("pause");

and now it goes straight to press any key to continue...

i tried setting the color to white (all 0's) and still takes me to the end .. no pixel found.
even at all set at 255 = black it couldn't find anything D:
Last edited by evilguyme; Sep 27th, 2009 at 11:36 am.
[IMG]http://i621.photobucket.com/albums/tt298/evilguyme/StickMovie.gif[/IMG]
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,400
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 113
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

Re: [HELP-CODE]Scanning Screen for pixel color

 
0
  #4
Sep 27th, 2009
One thing you may want to bear in mind, the GetPixel function is very slow, so you could literally be waiting 10 minutes before it finds the pixel. To demonstrate just how slow... try executing this code.
  1. int main() {
  2. COLORREF tofind = RGB(255, 0, 0);
  3. COLORREF col;
  4.  
  5. HDC hdc = GetDC(NULL);
  6.  
  7. for (int y = 0; y < 801; ++y) {
  8. for (int x = 0; x < 1280; ++x) {
  9. col = GetPixel( hdc, x, y );
  10. SetPixel( hdc, x, y, RGB(255,0,0) );
  11. }
  12. }
  13. }
Last edited by William Hemsworth; Sep 27th, 2009 at 11:26 am.
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 37
Reputation: evilguyme is an unknown quantity at this point 
Solved Threads: 0
evilguyme evilguyme is offline Offline
Light Poster

Re: [HELP-CODE]Scanning Screen for pixel color

 
0
  #5
Sep 27th, 2009
hmm ... then what's a good alternative to GetPixel()?
[IMG]http://i621.photobucket.com/albums/tt298/evilguyme/StickMovie.gif[/IMG]
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 1,400
Reputation: William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of William Hemsworth has much to be proud of 
Solved Threads: 113
Sponsor
William Hemsworth William Hemsworth is offline Offline
Nearly a Posting Virtuoso

Re: [HELP-CODE]Scanning Screen for pixel color

 
0
  #6
Sep 27th, 2009
Originally Posted by evilguyme View Post
hmm ... then what's a good alternative to GetPixel()?
Learn how to use bitmaps, take a screenshot, and lock the bitmap pixels to gain fast access to them.
Last edited by William Hemsworth; Sep 27th, 2009 at 4:36 pm.
I need pageviews! most fun profile ever :)
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 37
Reputation: evilguyme is an unknown quantity at this point 
Solved Threads: 0
evilguyme evilguyme is offline Offline
Light Poster

Re: [HELP-CODE]Scanning Screen for pixel color

 
0
  #7
Sep 28th, 2009
oooh that way...

hmm there doesn't seem to be a perfect tut out there..

i understand how to create an object of the bitmap and use btblts or whatever that API is.

but then how do i scan it for pixels?

google dint help...
[IMG]http://i621.photobucket.com/albums/tt298/evilguyme/StickMovie.gif[/IMG]
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 118
Reputation: marco93 is infamous around these parts marco93 is infamous around these parts marco93 is infamous around these parts 
Solved Threads: 12
marco93 marco93 is offline Offline
Junior Poster

Re: [HELP-CODE]Scanning Screen for pixel color

 
-2
  #8
Sep 28th, 2009
> google dint help

???
It's a win32 FAQ for about 15 years (!)
See on Win32 grp for classic code
to scan very quickly pixels with GDI or GDI+
Last edited by marco93; Sep 28th, 2009 at 10:59 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 37
Reputation: evilguyme is an unknown quantity at this point 
Solved Threads: 0
evilguyme evilguyme is offline Offline
Light Poster

Re: [HELP-CODE]Scanning Screen for pixel color

 
0
  #9
Sep 28th, 2009
it gives me a page not found error..

maybe u can tell me what strings to search for in google?

cuz i searched for like 30 mins and dint find anything good... :O

edit : oh wait nvm i got the site to work.. but its hard navigating in that site... lemme try the search

edit 2: zomg!! i searched pixel there and got no results..

then i searched bitmap and got some 5 lame results...
Last edited by evilguyme; Sep 28th, 2009 at 11:54 am.
[IMG]http://i621.photobucket.com/albums/tt298/evilguyme/StickMovie.gif[/IMG]
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,826
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: [HELP-CODE]Scanning Screen for pixel color

 
0
  #10
Sep 28th, 2009
Originally Posted by evilguyme View Post
i searched pixel there and got no results..

then i searched bitmap and got some 5 lame results...
Don't pay any attention to anything Marco93 says. We are still waiting for his first descent post.

Perhaps this can help you
Reply With Quote Quick reply to this message  
Reply

Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC