Recent

Author Topic: [SOLVED]Comparing TGaphicColor and TColor  (Read 280 times)

BubikolRamios

  • Sr. Member
  • ****
  • Posts: 380
[SOLVED]Comparing TGaphicColor and TColor
« on: January 10, 2026, 07:13:31 pm »
EDIT: Ehh sorry. It is not .colorLabel.color but .colorLabel.font.color to check. Then, obviously, works.

First is TGaphicColor second TColor
No errors, just does not get true at all, but it should as colors are the same.
Any suggestion ?
Code: Pascal  [Select][+][-]
  1. image: TBGRABitmap;    
  2.  
  3. if ((image.Canvas.Pixels[x,y] = form1.colorLabel.color) then
  4.  
« Last Edit: January 10, 2026, 07:46:14 pm by BubikolRamios »
lazarus 3.2-fpc-3.2.2-win32/win64

wp

  • Hero Member
  • *****
  • Posts: 13350
Re: [SOLVED]Comparing TGaphicColor and TColor
« Reply #1 on: January 10, 2026, 08:00:15 pm »
From the graphics unit:
Code: Pascal  [Select][+][-]
  1. type
  2.   TColor = TGraphicsColor;
Thus, TColor and TGraphicsColor are the same. TGraphicsColor is declared in unit GraphType which does not belong to the LCL. This way the usual colors can be used also in non-LCL applications (provided that package LazUtils is included).

As for your "if" never getting true for the same color: maybe the colors are different by a tiny amound? maybe there is a difference in the 4th byte which is used in the LCL to identify system colors. In BGRABitmap, the 4th byte, however, is used for the alpha channel.

Just set a breakpoint on the "if" and inspect the colors, ideally in hex, so that you can identify the 4th byte. If the debugger refuses to extract the values introduce two temporary variables to which you assign the colors:
Code: Pascal  [Select][+][-]
  1. var
  2.   c1, c2: string;
  3. ...
  4.   c1 := Format('%.8x', [image.Canvas.Pixels[x, y]);  // Use strings for Hex presentation (or in Laz 4 switch the debugger to hex)
  5.   c2 := Format('%.8x', [form1.colorLabel1.color]);
  6.   if ((image.Canvas.Pixels[x,y ] = form1.colorLabel.color) then  // <--- put a breakpoint on this line and inspect c1 and c2

If form1.colorLabel.color is a system color you could convert it to its rgb value before comparing:
Code: Pascal  [Select][+][-]
  1.   if ((image.Canvas.Pixels[x,y] = ColorToRGB(form1.colorLabel.color)) then

 

TinyPortal © 2005-2018