PDA

View Full Version : GetPixel(); etc. question



TravisV10
10-02-2008, 01:10 AM
I'm working on a little color clicker and I need some help.

When I try to use GetPixel(); to find a color it doesn't work. I'm positive I used all the right parameters.

Do I have to download a color library or something? I'm somewhat new to C++.

Thanks!
-Travis V10

Raskolnikov
10-02-2008, 01:29 AM
Pmed you on v10online.com...

I think you should use java. I researched GetPixel, and its for pictures.. Unless you can take a screenshot of the screen, your kind of screwed...

Cut em2 it

bullzeye95
10-02-2008, 01:48 AM
Not true. It should work if you input the correct DC and coordinates...

I'm not a C++ programmer, but could you show how you used it? I can probably help.

TravisV10
10-02-2008, 08:42 PM
[Linker error] undefined reference to `GetPixel@12'

boberman
10-02-2008, 09:52 PM
[Linker error] undefined reference to `GetPixel@12'

You need to link to gdi32.dll. This is done differently depending on what compiler you are using. With g++ you add -lgdi32 to the compile line.

TravisV10
10-02-2008, 09:58 PM
You need to link to gdi32.dll. This is done differently depending on what compiler you are using. With g++ you add -lgdi32 to the compile line.

Dev C++.

BTW Boberman, ScarPP is amazing! :)

EDIT: I know this is a newbie question: Where do I add it? My file is just colors.cpp. Do I need to make a .h file or something??

boberman
10-02-2008, 10:25 PM
Dev C++.

BTW Boberman, ScarPP is amazing! :)

EDIT: I know this is a newbie question: Where do I add it? My file is just colors.cpp. Do I need to make a .h file or something??

Why thank you :D

In dev c++ (which uses a mingw version of g++, pretty much g++) its project->project options->Parameters and under linker you add the -lgdi32

TravisV10
10-02-2008, 10:28 PM
Why thank you :D

In dev c++ (which uses a mingw version of g++, pretty much g++) its project->project options->Parameters and under linker you add the -lgdi32

Ahhh! It worked! :D What color output is it? Like how can I read the color? (I know I would use cout to look at it but its not like a Photoshop color XD ) I know I really sound stupid.

Will I need to do this again for any other color recognition stuff? (Or mouse moving and stuff. I'm using most of the things you used in ScarPP but just writing it myself.

bullzeye95
10-02-2008, 10:38 PM
It's just like what scar uses; a single number that is #bbggrr.

TravisV10
10-03-2008, 08:01 PM
Okay I have another question.

I'm trying to do FindColorTolerance. Can someone explain how to extract Red Green and Blue from RGB and how would I do the tolerance?

Thanks!

bullzeye95
10-03-2008, 08:32 PM
You would extract it like this: (sorry, I may be totally off with the syntax, because, as I said, I'm not a c++ coder)

void getRGB(int color, int &r, int &g, int &b)
{
r = color & #ff;
g = (color >> 8) & #ff;
b = (color >> 16) & #ff;
}

TravisV10
10-03-2008, 08:52 PM
I've heard GetRValue(),GetGValue() and GetBValue() are the best to use.

How would I use this to find tolerance?

bullzeye95
10-03-2008, 09:13 PM
Alright, those work too. I wasn't sure if those were part of the windows API, or just something included in Delphi, so I didn't mention them. As for finding tolerance, CTS 0 works like this: you find the RGB values of both the colors you want to compare, then check if the difference between the pairs of each of the values is less than or equal to the tolerance (abs(R2 - R1) <= Tol, etc.). CTS 1 works by calculating the square root of (R1 - R2)^2 + (G1 - G2)^2 + (B1 - B2)^2, and checking if that is less than or equal to the tolerance provided.
I'm not exactly sure how the other two work.

TravisV10
10-03-2008, 11:18 PM
I FINISHED FIND COLOR TOLERANCE! :DDDD I'm so happy!

Okay how do I include other files in my project?