help on pixels
i'm kinda a noob but i know the basics of windows programming and c++. what i'm trying to figure out is how to use GetPixel without getting a lot of errors. i'm trying to make a small program that gets the color of a pixel and simply print it out. but i can't find a working example anywhere. can someone give me some help.
also plz don't refer me to msdn i've gone there but thats no help to a beginner. that just defines it it doesn't show how to use it.
There's a small example in this thread which gets the pixel value at the current cursor position. A board search should give some more information/examples.
>>how to use GetPixel without getting a lot of errors<<
It makes it much easier for us to help you if you post the problematic code and any errors you're getting.
>>don't refer me to msdn i've gone there but thats no help to a beginner<<
Although it can be somewhat daunting at first stick with msdn; your perseverance will be rewarded.
Welcome to the boards. :)
thx for the welcome :D
"It makes it much easier for us to help you if you post the problematic code and any errors you're getting."
ok i used that code in that other topic. i copied and pasted it into a new file and compiled it. thats all thats in there. i get the following errors.
getpixel.cpp<2>: Error: missing decl-specifier-seq for declaration of 'COLORREF'
getpixel.cpp<3>: Error: missing decl-specifier-seq for declaration of 'HDC
getpixel.cpp<4>: Error: missing decl-specifier-seq for declaration of 'POINT'
getpixel.cpp<6>: Error: missing decl-specifier-seq for declaration of 'GetCursorPos'
getpixel.cpp<7>: Error: missing decl-specifier-seq for declaration of 'hdcScrn'
the error weren't copied and pasted because they were in my command prompt so any spelling errors are on me. but this is a start i guess. i don't know what the errors mean at all or how to fix them. i'm guessing i need to include code lines but i'm gonna take it one step at a time.
You need to include that header before you start using things from it.
new errors...but less is good
Error 42: Symbol Undefined _DeleteDC@4
Error 42: Symbol Undefined _GetPixel1@12
Error 42: Symbol Undefined _CreateDCA@16
You have to link to the gdi32.lib library.
Depends on your compiler. You should consult the documentation or tell us what compiler you use.
Look at the GDI-programs (script is in German). Perhaps they might help you understanding GDI.
my compiler - Digital Mars C/C++ Compilers
i have dev-c++ also but i don't use it cuz i get more errors but when i compile the same code with DM it compiles.
thx for the link it looks like the stuff i'm looking for. to google to translate...
by the windows header include, i have not heard of that compiler but i tried that in vc after removing it from my link list in the project settings and it still ran.
#pragma comment(lib, "gdi32.lib")
also i am using GetPixel, you can kinda see how it works a little bit i posted my code in
i am using the info for processing but in my example you can just use the values it returns to print out or whatever.
hope this helps
thx now it compiles with no errors
now all i have to do is make this
#pragma comment(lib, "gdi32.lib")
print out the color value...seems easy enough
dont forget to break down the colorref value into the red green and blue values because the colorref value is just a hex value and there are macros to grab those hex values and turn them into bits so you can display them.
oh yeah those macros are GetRValue() GetBValue() and GetGValue() and you can use them something like this.
but you probably already knew that.
COLORREF pixColor = GetPixel(someHdc,13,13);
sprintf(chPixColor,"R=%d G=%d B=%d",GetRValue(pixColor),GetGValue(pixColor),GetBValue(pixColor));
MessageBox(hwnd,chPixColor,"Pixel Color @ x=13 y=13",0);
dang now i have to figure out how to do that lol