I have no clue how this function is used, i only know its parameters. Can anyone tell me how its supposed to be implemented? I've searched all kinds of places to figure it out but i cant find anything lol
Printable View
I have no clue how this function is used, i only know its parameters. Can anyone tell me how its supposed to be implemented? I've searched all kinds of places to figure it out but i cant find anything lol
At a guess I would say that it would return the ARGB colour value at a co-ord.
[edit] At least that is what the name would suggest [/edit]
Is this what you were looking for?
http://msdn2.microsoft.com/en-us/lib...wt(VS.71).aspx
no, like what to include in order to use it, and do i have to do anything else to use it as well?
Did you not take the time to look on the site? It's a member of the CImage class. All the requirements are on this page.
http://msdn2.microsoft.com/en-us/lib...y5(VS.80).aspx
Could MSDN be any slower, geez. But to answer your question that function returns a long word with the Red Green and Blue value of a pixel in an unsigned long value at the given coordinate. How you use it is up to you, you call the function and do something with it.
I would think that an image editing program could implement a color dropper, burn, etc tool to change the color of the pixels around it, and many other implementations I assume.
here's the definition of COLORREF to show you how to interpret the value returned
http://msdn2.microsoft.com/en-us/library/aa923096.aspx
ok i finally found an article that's sort of about GetPixel(), and this is what it had in the example:
and he included windows.h for it, but when i run this code i get an error that says "Undefined reference to GetPixel@12". Anyone know what might be wrong there?Code:int x,y;
unsigned char pixels[30][100];
HDC hdc = GetDC(NULL);
for(y=SY;y<SY+30;y++)
for(x=SX;y<SX+100;x++)
if(GetPixel(hdc,x,y)==0)
cout << "black" << endl;
You need to add the "gdi32.lib" in your project properties
now it says build error and thats it
What compiler and ide are you using. if you are using msw you have to include "gdi32.lib", if you are using gcc/g++ you have to use "gdi32lib.a". Most IDEs allow you to just put "gdi32. And it will look in the library path for it, others may not.
I'm using dev c++ and i dont really know what the ide is, i think its mingw/gcc or something like that
okay, there should be a place where you can change the build options of a project. Look for "linker settings" or "library settings" and add "gdi32"
I already had that there but it was "gdi32.lib" and it comes with this exact error
and its the same when i take .lib offCode:C:\Dev-Cpp\Makefile.win [Build Error] ["HTS] Error 1
Under Tools -> Compiler Options
Check the box for: Add these commands to the linker command line
and then add: -lgdi32
ok i got it, i didnt need to put it in the project properties, i had to put it where swoopy specified
ok so if i wanted to check if a pixel is white, what would i have to do? I dont understand the numbers GetPixel returns. Like "13026246" - its not enough numbers to be an RGB value and "4294967295" - thats to many numbers to be an RGB value. I really don't get it lol
Well if you looked at the link Indigo posted, it shows you how to interpret a COLORREF. The lower eight bits are for red, the next eight for green, and the next eight are blue. The last eight are zero. So one way to break up the parts would be to use bit shifting. Once you do this, each part (red, green, and blue) will be a value from 0 to 255.
I think there are also some window macros which will break up a COLORREF. Or you could also use the bitset class from the standard library to make things easier.Code:COLORREF color = GetPixel(hdc, x, y);
unsigned int r = color & 0xff;
unsigned int g = (color & 0xff00) >> 8;
unsigned int b = (color & 0xff0000) >> 16;
cout << "red: " << r << endl;
cout << "green: " << g << endl;
cout << "blue: " << b << endl;
>ok so if i wanted to check if a pixel is white, what would i have to do?
White would be a 255 for all three components (red=255, green=255, blue=255). Red of course would be (red=255, green=0, blue=0). So to check for white using the above code:
Or you could also write:Code:if (r == 255 && g == 255 && b == 255)
{
//Pixel is white
}
Code:if (color == 0xffffff)
{
//Pixel is white
}
it doesnt work, neither doesCode:0xffffff
for blackCode:0x000000
and for some reason r g b are all getting the value 255 every time no matter what.
do you know what could cause this?
[EDIT] sorry for the double post
COLORREF is a waste of finger time, just use DWORD. :) (It's the same thing. ;))
Try this instead: It may mork and may not, so hey...
Code:DWORD color = GetPixel(hdc, x, y);
unsigned int r = GetRValue(color);
unsigned int g = GetGValue(color);
unsigned int b = GetBValue(color);
cout << "red: " << r << endl;
cout << "green: " << g << endl;
cout << "blue: " << b << endl;
its the same thing with that to :S maybe if you all look at my code something may catch your eye that im doing wrong lol.
Code:int x,y,SX=347,SY=375;
unsigned char pixels[30][100];
unsigned int r,g,b;
HDC hdc = GetDC(NULL);
DWORD color=GetPixel(hdc,x,y);
for(y=SY;y<SY+30;y++)
for(x=SX;x<SX+100;x++)
{
color;
r=GetRValue(color);
g=GetGValue(color);
b=GetBValue(color);
if(r==255 && g==255 && b==255)
cout << "white ";
else if(r==0 && g==0 && b==0)
cout << "black ";
}
Hmm, what's this? ;)
Code:int x,y,SX=347,SY=375;
unsigned char pixels[30][100];
unsigned int r,g,b;
HDC hdc = GetDC(NULL);
DWORD color=GetPixel(hdc,x,y);
Sleep(2000);
for(y=SY;y<SY+30;y++)
for(x=SX;x<SX+100;x++)
{
color;
r=GetRValue(color);
g=GetGValue(color);
b=GetBValue(color);
if(r==255 && g==255 && b==255)
cout << "white ";
else if(r==0 && g==0 && b==0)
cout << "black ";
}
that does the GetPixel() function doesnt it?
No, this does:
You both create and assign color on the same line.Code:int x,y,SX=347,SY=375;
unsigned char pixels[30][100];
unsigned int r,g,b;
HDC hdc = GetDC(NULL);
DWORD color=GetPixel(hdc,x,y);
Sleep(2000);
for(y=SY;y<SY+30;y++)
for(x=SX;x<SX+100;x++)
{
color;
r=GetRValue(color);
g=GetGValue(color);
b=GetBValue(color);
if(r==255 && g==255 && b==255)
cout << "white ";
else if(r==0 && g==0 && b==0)
cout << "black ";
}
ah ok i see your point, i'll give it a shot.
What are you trying to get an image of anyway? If it's another window then you need to set your hdc to it's hdc, and start getting the pixels at 0x0.
i fixed it here's what ive got, and ya im getting the pixel values of an image in a browser
Code:int x,y,pixel=-1,wpix,offset;
unsigned char pixels[30][100];
unsigned int r,g,b;
HDC hdc = GetDC(NULL);
DWORD color;
Sleep(3000);
for(y=SY;y<SY+30;y++)
for(x=SX;x<SX+100;x++)
{
pixel=pixel+1;
color=GetPixel(hdc,x,y);
r=GetRValue(color);
g=GetGValue(color);
b=GetBValue(color);
if(r==255 && g==255 && b==255)
// white pixel
can beCode:pixel=pixel+1;
:)Code:pixel += 1;
Or
orCode:pixil++;
Code:++pixel;