SRL Archive - C/C++ Help and Tutorials

GetPixel(); etc. question


TravisV10

2008-10-01 21:10:14

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

2008-10-01 21:29:35

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

2008-10-01 21:48:15

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

2008-10-02 16:42:21

[Linker error] undefined reference to `GetPixel@12'

boberman

2008-10-02 17:52:29

From: born2code
[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

2008-10-02 17:58:01

From: boberman
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

2008-10-02 18:25:34

From: born2code
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

2008-10-02 18:28:34

From: boberman
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

2008-10-02 18:38:23

It's just like what scar uses; a single number that is #bbggrr.

TravisV10

2008-10-03 16:01:26

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

2008-10-03 16:32:59

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

2008-10-03 16:52:12

I've heard GetRValue(),GetGValue() and GetBValue() are the best to use.

How would I use this to find tolerance?

bullzeye95

2008-10-03 17:13:24

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

2008-10-03 19:18:30

I FINISHED FIND COLOR TOLERANCE! :DDDD I'm so happy!

Okay how do I include other files in my project?