Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Red, Green, Blue color of panel? 1

Status
Not open for further replies.

simmo09

Programmer
Apr 22, 2009
82
GB
Yo, im trying to get the color of red, green and blue by byte - i have 3 labels lblRed, lblGreen, lblBlue, and 3 scrollbars.

i want to show the correct value in each label 0-255 and also scrollbar positions, hope this makes sense:

Code:
procedure TForm1.RetrieveCurrentSkinColors;
var
  R,G,B: Byte;
begin
  {assign each color byte value from the panel}
  R:= Panel1.Color;
  G:= Panel1.Color;
  B:= Panel1.Color;

  {set label captions and scrollbar positions}
  lblRed.Caption:= IntToStr(R);
  lblGreen.Caption:= IntToStr(G);
  lblBlue.Caption:= IntToStr(B);

  barRed.Position:= R;
  barGreen.Position:= G;
  barBlue.Position:= B;

  {put retrieved color into panel}
  Panel2.Color:= Panel1.Color;
end;

doesnt seem to work, basically i just need to find the rgb value for each color in panel1, red, green and blue.

Thanks
 
i just need to find the rgb value for each color in panel1, red, green and blue.

2nd, 3rd, and 4th bytes in your TColor value.

Measurement is not management.
 
never mind, i found this at torry:

Code:
{
 RGB values to TColor
 RGB Werte zu TColor
}

procedure TForm1.Button1Click(Sender: TObject);
begin
  Edit1.Color := RGB(58, 110, 165);
end;

{
 TColor to RGB values
 TColor zu RGB Werte
}

procedure TForm1.Button2Click(Sender: TObject);
var
  Color: Longint;
  r, g, b: Byte;
begin
  Color := ColorToRGB(Edit1.Color);
  r     := Color;
  g     := Color shr 8;
  b     := Color shr 16;
  label1.Caption := ' Red  : ' + IntToStr(r) +
    ' Green: ' + IntToStr(g) +
    ' Blue : ' + IntToStr(b);
end;
 
Okay...

What I was saying is that you will find what you are wanting to know in those particular bytes of the TColor value. TColor is a 4-byte value.

Byte 2 = Red
Byte 3 = Green
Byte 4 = Blue

Now you should be able to redefine/assign the TColor value to an array[1..4] of byte and then access the data you need.

Measurement is not management.
 
Not necessarily addressed to the OP, but more commenting on the code that was copied. One thing that seems to be lost is the idea of simplicity. I'll admit that I didn't end up getting the whole story out of the docs (2-4 bytes as it appears in a LSB setup, which means 1-3 in a MSB one as you would have to access it). But even a task like this ended up being made more complex by throwing it into a function - I wouldn't even put it into a function unless it was called a BUNCH by a lot of different apps.

Maybe this is another symptom of the "just get it done as fast as possible" mentality and not worry about other factors. If it works go with it, if you can copy it go with it and not seek to learn how to do it yourself, etc.

Code:
color_type = (ctRed, ctGreen, ctBlue);

function SetColorChange(incolor: TColor; position: integer; color: color_type): TColor;
{ changes a specific color byte in a TColor }
type
  marray = array[0..3] of byte;
begin
  Marray(incolor)[Integer(color)] := position;
  Result := incolor;
end;

procedure TForm1.sbRedChange(Sender: TObject);
 { scroll bar change - signifies the red color }
begin
  Panel1.Color := SetColorChange(Panel1.Color, sbRed.Position, ctRed);
  Label1.Caption := '$' + IntToHex(Integer(Panel1.Color), 8);
end;

Measurement is not management.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top