Identify Colour Change

hi, I need some help with identifying colour change at a selected spot on the screen, like 100x100 for example and it will get the colour and display what colour it is like Hue, RGB or HMTL code colour.

you know in Paint Programs you have this ink tool which copys the colour, you move your mouse over where you want to select that colour and it will use that colour, thats what am after.

I need to know if the colour has changed or not in a selected area of the screen.

could anyone provide code?

thanks,
Sal.
LVL 2
SaLzAsked:
Who is Participating?
 
JohnjcesCommented:
Here's a simpler approach.

function GetScreenPixelColor(X, Y : Integer): Integer;
var
DeskTop : HDC;
begin
 Result := -1;
 DeskTop := GetWindowDC(GetDesktopWindow);
 if DeskTop > 0 then
  Result := GetPixel(Desktop, 100, 100);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
color : Integer;
begin
 edit1.text := IntToHex(GetScreenPixelColor(100, 100), 8);
end;
0
 
JustinWillisCommented:
Hello, I put this together which I think does what you want, once you have it as a TColor you should be able to do whatever you want with it but I have just put it to a label for demo.  Not sure what you mean by 100x100 but you could always abort the code using exit if p.x and p.y is outside of set coords, this seems pretty simple so won't insult you with example unless you need it.

procedure TForm1.Timer1Timer(Sender: TObject);
var
  DeskTopDC: HDc;
  DeskTopCanvas: TCanvas;
  TheColor:Tcolor;
  P:Tpoint;
begin
  DeskTopDC := GetWindowDC(GetDeskTopWindow);
  DeskTopCanvas := TCanvas.Create;
  DeskTopCanvas.Handle := DeskTopDC;

  GetCursorPos(P);
  TheColor := DeskTopCanvas.Pixels[p.x,p.y];
  label1.caption := ColorToString(TheColor);

  ReleaseDC(GetDeskTopWindow,DeskTopDC);
  DesktopCanvas.Free;
end;

Hope this solves your prob.
Regards,
Justin Willis.
0
 
JustinWillisCommented:
Oh btw you may want to find out also how to change the mouse cursor to a dropper or something if you actually need that functionality but I am guessing you just want x,y access to colour on screen so should all be good...
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
JohnjcesCommented:
Woops...

Try this

function GetScreenPixelColor(X, Y : Integer): Integer;
var
DeskTop : HDC;
begin
 Result := -1;
 DeskTop := GetWindowDC(GetDesktopWindow);
 if DeskTop > 0 then
  Result := GetPixel(Desktop, X, Y);
end;
0
 
SaLzAuthor Commented:
>JustinWillis
>>this seems pretty simple so won't insult you with example unless you need it.

am going to go into this cos at the moment am bored and got some time on my hands, so am gonna break this sentence up and give some meaning.

"this seems pretty simple" this here is saying its very simple, only a fool could miss it,
"so won't insult you with example" this here has intent to insult, if he provides an example it will be an insult.
"unless you need it" this here is an open offer to be insulted, if I request to provide an example, it would be an insult.

this is what we call a sentence contact, the above is a break down of the contract, if I was to ask for the example I will be insulted, if I don't ask, I don't get insulted..

the contact is an open/close contract, JustinWillis has made it with intent to insult, like saying if you don't move I wont shoot you, the person moves he gets shot, this is a sentence contract, you sign it there and then with your actions, you don't move you signed it, you move you signed it, with one catch, you don't move you have fulfilled a contract you will not be shot, if you move you have broken the contract, you will be shot, the shooter with this now has no guilt about shooting the person, it was a contract and as such both partys have signed it with there actions, nobodys liable, both partys knew about the contract and what might happen.

what do I do with his contract, at the moment, to be honest his contract has already been used, I can't do anything because he has wasted his sentence contract, its was already sealed when he posted his comment, it was used up before I even had time to read it.

he has wasted his own contract, in my question I asked for examples, so it voided his contract. because my contract came before his contract which my contract already had the outcome of his contract.

when a contract is used up before the person has been able to sign, this is what we call a sealed contract, its voided there and then, it happens when the person doesn't coving all there bases, its like the shooter shooting him self in the foot soon after saying the contract.

how can I be insulted now, your contract is used up, you wasted your contract, all it shows us you didn't cover your bases JustinWillis. it also shows us that you had intent to insult, when you didn't need to, and it shows us what kind of a person you are, it also says what kind of a person I am by typing all this.

why make a sentence contract when u didn't need to? what was the point? adding 2 much info, not adding enough info?

as a final word for ya JustinWillis, just choose your words carefully, don't have intent and always read the question and make sure that your bases are cover, this time you striked your self out, for this question, in a way you set your self up to insult me, tut tut.

Johnjces, I like 1 line functions makes everything so easy to deal with.

thanks.
Sal.
0
 
JustinWillisCommented:
lol, wow, u are bored! well reading my response again I can kinda see where you are coming from, apologies, it was not my intention to insult or offend you! just trying to help, what I was basically trying to say is that I had started you off with the answer and you probably do not need me to do the whole thing for you as you appear to know what you are talking about based on your initial question and you will want to sculpt the code anyway for your exact purpose.  

I do not care about the points or getting an Accepted Answer, I pay for my EE membership anyway, I am just trying to give something back to the EE community for the help I have received.

I am suprised by your response and offer an apology once again.

Regards,
JustinWillis.
0
 
SaLzAuthor Commented:
its ok, where kool :-)

Sal.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.