Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Identify Colour Change

Posted on 2005-04-11
7
Medium Priority
?
303 Views
Last Modified: 2010-05-18
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.
0
Comment
Question by:SaLz
  • 3
  • 2
  • 2
7 Comments
 
LVL 1

Assisted Solution

by:JustinWillis
JustinWillis earned 80 total points
ID: 13755749
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
 
LVL 1

Expert Comment

by:JustinWillis
ID: 13755765
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
 
LVL 18

Accepted Solution

by:
Johnjces earned 1920 total points
ID: 13755968
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 18

Assisted Solution

by:Johnjces
Johnjces earned 1920 total points
ID: 13755987
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
 
LVL 2

Author Comment

by:SaLz
ID: 13761558
>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
 
LVL 1

Expert Comment

by:JustinWillis
ID: 13761705
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
 
LVL 2

Author Comment

by:SaLz
ID: 13762517
its ok, where kool :-)

Sal.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question