| | |
[HELP-CODE]Scanning Screen for pixel color
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2009
Posts: 37
Reputation:
Solved Threads: 0
so far i have this code..
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.
C++ Syntax (Toggle Plain Text)
#include "stdafx.h" #include <iostream> #include <windows.h> #include <string> using namespace std; int main () { const int r1 = 175; const int g1 = 163; const int b1 = 134; HWND hwnd = FindWindow(NULL,"Test - Microsoft Visual Studio"); SetForegroundWindow(hwnd); HDC hdc = GetDC(hwnd); POINT lame; lame.x = 0; lame.y = 0; int x = lame.x; int y = lame.y; for (int i = 0; i < 1280; i++) { x = i; y = 0; COLORREF col = GetPixel(hdc,lame.x,lame.y); int red1 = GetRValue(col); int green1 = GetGValue(col); int blue1 = GetBValue(col); if (x == 1280) { y = lame.y++; i = 0; } if (y == 801) { system("pause"); } if (red1 == r1 && green1 == g1 && blue1 == b1) { cout << "Pixel found at: \t" << "X: "<< x << "\t\t" << "Y: " << y << "\n"; system("pause"); } } system("pause"); return 0; }
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.
•
•
Join Date: Mar 2008
Posts: 1,400
Reputation:
Solved Threads: 113
This code is confusing, that's your main problem. I don't understand the need for
If you want to loop through every pixel from point (0,0) and (1280,801) to find a pixel, do this: Hope this helps.
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:
C++ Syntax (Toggle Plain Text)
/* Untested code */ COLORREF tofind = RGB(175, 163, 134); COLORREF col; for (int y = 0; y < 801; ++y) { for (int x = 0; x < 1280; ++x) { col = GetPixel( hdc, x, y ); if ( col == tofind ) { cout << "Pixel found at: \t" << "X: "<< x << "\t\t" << "Y: " << y << "\n"; cin.ignore(); } } } cin.ignore();
Last edited by William Hemsworth; Sep 27th, 2009 at 10:38 am.
I need pageviews! most fun profile ever :)
•
•
Join Date: Sep 2009
Posts: 37
Reputation:
Solved Threads: 0
lemme try that. thnx for the code 
that still doesn't work...
still exits program at the end.
so i added
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:

that still doesn't work...
still exits program at the end.
so i added
C++ Syntax (Toggle Plain Text)
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.
•
•
Join Date: Mar 2008
Posts: 1,400
Reputation:
Solved Threads: 113
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.
C++ Syntax (Toggle Plain Text)
int main() { COLORREF tofind = RGB(255, 0, 0); COLORREF col; HDC hdc = GetDC(NULL); for (int y = 0; y < 801; ++y) { for (int x = 0; x < 1280; ++x) { col = GetPixel( hdc, x, y ); SetPixel( hdc, x, y, RGB(255,0,0) ); } } }
Last edited by William Hemsworth; Sep 27th, 2009 at 11:26 am.
I need pageviews! most fun profile ever :)
•
•
Join Date: Sep 2009
Posts: 37
Reputation:
Solved Threads: 0
hmm ... then what's a good alternative to GetPixel()?
•
•
Join Date: Mar 2008
Posts: 1,400
Reputation:
Solved Threads: 113
Last edited by William Hemsworth; Sep 27th, 2009 at 4:36 pm.
I need pageviews! most fun profile ever :)
•
•
Join Date: Sep 2009
Posts: 37
Reputation:
Solved Threads: 0
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...
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...
•
•
Join Date: Apr 2008
Posts: 118
Reputation:
Solved Threads: 12
> 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+
???
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.
•
•
Join Date: Sep 2009
Posts: 37
Reputation:
Solved Threads: 0
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...
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.
•
•
•
•
i searched pixel there and got no results..
then i searched bitmap and got some 5 lame results...
Perhaps this can help you
![]() |
Similar Threads
- Scan a pixel for a color in C++? (C++)
- C# Finding a pixel by color (C#)
- [Help] Checking and Changing Pixel Color (VB.NET)
- pixel color changing (C++)
- Changing a pixel color that is "close" to another color (Pascal and Delphi)
Other Threads in the C++ Forum
- Previous Thread: How to convert a string to ASCII ?
- Next Thread: how to complile in code blocks
| Thread Tools | Search this Thread |
api array based binary c++ c/c++ calculator char char* class classes code coding compile console conversion count database delete deploy desktop developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visualstudio win32 windows winsock wordfrequency wxwidgets






