Converts a TColor value into an RGB representation of the color.
function ColorToRGB(Color: TColor): Longint;
Longint ColorToRGB(TColor Color);
Graphics
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.
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) 2008 CodeGear(TM). All Rights Reserved.
|
What do you think about this topic? Send feedback!
|