Arora
asked on
Getpixel
Hi,
I have loaded bitmap on the formview. I want the pixel color of bitmap where i left click the mouse button?
I wrote the following code in Lbuttondown() function but it is not working
COLORREF ref;
CDC *pDC = GetDC();
ref = GetPixel(point.x, point.y);
let me know what is the problem and Answer
bye
Arora
I have loaded bitmap on the formview. I want the pixel color of bitmap where i left click the mouse button?
I wrote the following code in Lbuttondown() function but it is not working
COLORREF ref;
CDC *pDC = GetDC();
ref = GetPixel(point.x, point.y);
let me know what is the problem and Answer
bye
Arora
better post this question in the windows programming area. you'd get much more traffic. After doing this, delete this question.
Arnon David.
Arnon David.
your problem isn't so much where you post it(I know a LOT of programmers come to this section, including myself), it's with the GetDC call. Try this:
COLORREF c;
HDC dc = GetDC(hWnd);
c = GetPixel(x, y);
you can use point.x, point.y also if you choose, depends on how you handle the message. If this doesn work, send me the whole program, I'll figure it out! =)
~Aaron
COLORREF c;
HDC dc = GetDC(hWnd);
c = GetPixel(x, y);
you can use point.x, point.y also if you choose, depends on how you handle the message. If this doesn work, send me the whole program, I'll figure it out! =)
~Aaron
OOPS! I forgot one thing, GetPixel(dc, x, y); LoL, tiny mistake. ;-P
~Aaron
~Aaron
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Ever I used HDC of the window as follows
HDC DC;
DC = GetDC(m_hWnd);
GetPixel( DC,point.x, point,Y);
still the GetPixel function is not succeeding.
bye
Arora
Arora:
Can you get the above code to even compile? IF you're in your LBUTTONDOWN handler, then the compiler "thinks" the
line
DC = GetDC(m_hWnd);
is trying to call the CDC class's GetDC function and won't compile. BUT, if you write
DC = ::GetDC(m_hWnd);
then it compiles fine because the compiler now knows you want the WIN32 API function GetDC.
The code I listed in my proposed answer works (on my computer), BUT if you want to use the WIN32 API functions then write:
HDC DC;
DC = ::GetDC(m_hWnd);
COLORREF color = ::GetPixel(point.x,point.y );
This works on my computer.
Glenn
Can you get the above code to even compile? IF you're in your LBUTTONDOWN handler, then the compiler "thinks" the
line
DC = GetDC(m_hWnd);
is trying to call the CDC class's GetDC function and won't compile. BUT, if you write
DC = ::GetDC(m_hWnd);
then it compiles fine because the compiler now knows you want the WIN32 API function GetDC.
The code I listed in my proposed answer works (on my computer), BUT if you want to use the WIN32 API functions then write:
HDC DC;
DC = ::GetDC(m_hWnd);
COLORREF color = ::GetPixel(point.x,point.y
This works on my computer.
Glenn
OOPS! Change the above line to
COLORREF color = ::GetPixel(DC,point.x,poin t.y);
COLORREF color = ::GetPixel(DC,point.x,poin
ASKER