Tag Archives: Color

Small but smart colorpicker

Small but smart colorpicker

The small but smart color picker

This is my attempt at making a small but smart color picker. It has two modes and can be used for live color updating. The mode shown in image is Alphamode:= True, second mode will then be Alphamode:= False which will be more aimed at web design.

To set the colorpickers color use:
SetColor(Color, Alpha, Update) or SetColor(Color, Update) where Update is a boolean which if false will set old color to color value.

Alpha is a value between 0 and 255.

To get color value use GetColor. Alpha value is stored in RGBAlpha.

Download: Color Picker (260kB)

Mixing two colors

Just a quick tips for those of you needing to blend two colors. Usage is very easy.

// Usage  NewColor:= Blend(Color1, Color2, blending level 0 to 100);
function Blend(Color1, Color2: TColor; A: Byte): TColor;
var
  c1, c2: LongInt;
  r, g, b, v1, v2: byte;
begin
  A:= Round(2.55 * A);
  c1 := ColorToRGB(Color1);
  c2 := ColorToRGB(Color2);
  v1:= Byte(c1);
  v2:= Byte(c2);
  r:= A * (v1 - v2) shr 8 + v2;
  v1:= Byte(c1 shr 8);
  v2:= Byte(c2 shr 8);
  g:= A * (v1 - v2) shr 8 + v2;
  v1:= Byte(c1 shr 16);
  v2:= Byte(c2 shr 16);
  b:= A * (v1 - v2) shr 8 + v2;
  Result := (b shl 16) + (g shl 8) + r;
end;