Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!
Topics for particular software or systems: Start your topic link with the name of the application or system.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.
Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is no translation for that post!
[Solved] Lazarus - Grab the color of a pixel anywhere on a Form
Delphi, Lazarus, Free Pascal
(@hans)
Famed Member Admin
Joined: 12 years ago
Posts: 2859
Topic starter
September 17, 2018 1:16 AM
So I figured this out for a particular purpose - detecting theme colors - for which it proved useless.
However, I can see other applications for which this may be useful.
Note: Under the Cocoa widget set this will not work (at the time), it always returns the color black. It worked fine under Linux and I have not yet tested it under Windows.
procedure TForm1.GetPixelColor(X,Y:integer);
var
ValR2, ValG2, ValB2: Byte;
PixelColor : TColor;
begin
PixelColor := self.Canvas.Pixels[X,Y];
valR2 := GetRValue(PixelColor);
valG2 := GetGValue(PixelColor);
valB2 := GetBValue(PixelColor);
// Label1.Caption:='R='+IntToStr(valR2)+' G='+IntToStr(valG2)+' B='+IntToStr(valB2);
end;
Up to you if you want to display this in a label, or have it as a TColor return value, etc.