RAD Studio VCL Reference
|
Converts a TColor value into an RGB representation of the color.
function ColorToRGB(Color: TColor): Longint;
Longint ColorToRGB(TColor Color);
Call ColorToRGB to obtain an RGB representation of a color for using with Windows API calls. ColorToRGB strips away the information that is stored in the highest order bits about which palette to use for colors that are not always available.
C++ Examples:
/* The following code converts the color of the current form, Form1, to a Windows RGB value: */ int NumPaletteEntries = 20; TPaletteEntry FPaletteEntries[20]; void __fastcall TForm1::FormCreate(TObject *Sender) { GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, NumPaletteEntries, FPaletteEntries); Form1->Color = clMoneyGreen; } void __fastcall TForm1::Button1Click(TObject *Sender) { int Result = 0; int I = 0; TColor RealColor = Graphics::ColorToRGB(Form1->Color); while (I < NumPaletteEntries) { // with FPaletteEntries[I] do TColor paletteColor = RGB( FPaletteEntries[I].peRed, FPaletteEntries[I].peGreen, FPaletteEntries[I].peBlue); if (RealColor == paletteColor) { Label1->Caption = IntToStr(I); RedEdit->Text = IntToStr(FPaletteEntries[I].peRed); GreenEdit->Text = IntToStr(FPaletteEntries[I].peGreen); BlueEdit->Text = IntToStr(FPaletteEntries[I].peBlue); break; } I++; }; } void __fastcall TForm1::Button2Click(TObject *Sender) { Form1->Color = (StrToInt(RedEdit->Text) << 16) + (StrToInt(GreenEdit->Text) << 8) + (StrToInt(BlueEdit->Text)); }
Delphi Examples:
{ The following code converts the color of the current form, Form1, to a Windows RGB value: } const NumPaletteEntries = 20; var FPaletteEntries: array[0..NumPaletteEntries - 1] of TPaletteEntry; procedure TForm1.Button1Click(Sender: TObject); var I: Integer; Result: Integer; RealColor, paletteColor: TColor; begin Result := 0; I := 0; RealColor := Graphics.ColorToRGB(Form1.Color); while I < NumPaletteEntries do begin with FPaletteEntries[I] do begin paletteColor:= TColor(RGB(peRed, peGreen, peBlue)); if RealColor = paletteColor then begin Label1.Caption := IntToStr(I); RedEdit.Text:= IntToStr(peRed); GreenEdit.Text:= IntToStr(peGreen); BlueEdit.Text:= IntToStr(peBlue); Exit; end; end; Inc(I) end; end; procedure TForm1.Button2Click(Sender: TObject); begin Form1.Color:= StrToInt(RedEdit.Text) shl 16 + StrToInt(GreenEdit.Text) shl 8 + StrToInt(BlueEdit.Text); end; procedure TForm1.FormCreate(Sender: TObject); begin GetPaletteEntries(GetStockObject(DEFAULT_PALETTE), 0, NumPaletteEntries, FPaletteEntries); Form1.Color:= clMoneyGreen; end;
Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
|
What do you think about this topic? Send feedback!
|