我有幾個顏色列表(TColor)存儲在數組中,我喜歡使用HUE排序o Luminosity存在任何具有這種功能的delphi庫或組件或算法?顏色排序(調色板)由Hue和Luminosity,使用delphi
3
A
回答
6
Delphi中有一個叫GraphUtil
其中有一個叫SortColorArray
procedure SortColorArray(ColorArray: TColorArray; L, R: Integer;
SortType: TColorArraySortType; Reverse: Boolean = False);
此功能可以按色調,飽和度,亮度,紅,綠,藍的顏色列表功能單元。
,你可以通過這種方式
var
ColorList : TColorArray;
i : Integer;
begin
SetLength(ColorList,WebNamedColorsCount);
//fill the list the colors in this case using webcolors
for i := 0 to WebNamedColorsCount - 1 do
begin
ColorList[i].Value:=WebNamedColors[i].Value;
ColorList[i].Name :='';
end;
//sort the colors by HUE
SortColorArray(ColorList,0,WebNamedColorsCount-1,stHue,False);
//do your stuff here
end;
1
我做
type
TRGB = record
rgbRed, // Red intensity in [0, 1]
rgbGreen, // Green intensity in [0, 1]
rgbBlue: double; // Blue intensity in [0, 1]
end;
THSV = record
hsvHue, // Hue angle in [0, 360]
hsvSaturation, // Saturation in [0, 1]
hsvValue: double; // Value in [0, 1]
end;
function MaxComponent(const Color: TRGB): real;
begin
with Color do
result := max(max(rgbRed, rgbGreen), rgbBlue);
end;
function MinComponent(const Color: TRGB): real;
begin
with Color do
result := min(min(rgbRed, rgbGreen), rgbBlue);
end;
function Fix360(const a: Real): real;
begin
result := a;
if result > 360 then
while result > 360 do
result := result - 360
else if result < 0 then
while result < 0 do
result := result + 360;
end;
function RGBToHSV(const Color: TRGB): THSV;
var
cmax, cmin, cdiff: real;
begin
cmax := MaxComponent(Color);
cmin := MinComponent(Color);
cdiff := cmax - cmin;
with Color, result do
begin
// Hue
if cmax = cmin then
hsvHue := 0
else if cmax = rgbRed then
hsvHue := (60 * (rgbGreen - rgbBlue)/cdiff)
else if cmax = rgbGreen then
hsvHue := (60 * (rgbBlue - rgbRed)/cdiff) + 120
else
hsvHue := (60 * (rgbRed - rgbGreen)/cdiff) + 240;
hsvHue := Fix360(hsvHue);
// Saturation
if cmax = 0 then
hsvSaturation := 0
else
hsvSaturation := 1 - cmin/cmax;
// Value
hsvValue := cmax;
end;
end;
function HSVToRGB(const Color: THSV): TRGB;
var
hi: integer;
f, q, p, t: real;
begin
with Color do
begin
hi := floor(hsvHue/60) mod 6;
f := hsvHue/60 - floor(hsvHue/60);
p := hsvValue * (1 - hsvSaturation);
q := hsvValue * (1 - f * hsvSaturation);
t := hsvValue * (1 - (1 - f) * hsvSaturation);
case hi of
0: result := RGB(hsvValue, t, p);
1: result := RGB(q, hsvValue, p);
2: result := RGB(p, hsvValue, t);
3: result := RGB(p, q, hsvValue);
4: result := RGB(t, p, hsvValue);
5: result := RGB(hsvValue, p, q);
end;
end;
end;
到RGB和HSV之間的轉換。現在你可以很容易地得到任何顏色的色調,排序應該是微不足道的。
更新
如何獲取從TColor
一個TRGB
?只要做到
function PascalColorToRGB(Color: TColor): TRGB;
begin
Color := GetSysColor(Color);
with result do
begin
rgbRed := GetRValue(Color)/255;
rgbGreen := GetGValue(Color)/255;
rgbBlue := GetBValue(Color)/255;
end;
end;
如何獲取從TRGB
一個TColor
?只要做到
function GetPascalColor(const Color: TRGB): TColor;
begin
with Color do
result := Windows.RGB(round(255*rgbRed),
round(255*rgbGreen),
round(255*rgbBlue));
end;
相關問題
- 1. 排序的顏色陣列通過調色板
- 2. 顏色色板
- 3. 在r中調整顏色調色板
- 4. 對顏色/顏色值進行排序
- 5. RibbonWindow Office 2007黑色主題的調色板(使用的顏色)?
- 6. 獲取一些顏色的調色板
- 7. Seaborn調色板 - 防止顏色回收
- 8. 改變顏色的調色板中ggplot
- 9. Seaborn圖表顏色與調色板指定的顏色不同
- 10. 顏色選擇器(調色板)顯示所有顏色
- 11. 使用HSV顏色空間更改白色和黑色顏色
- 12. 使用調色板更改圖像按鈕顏色
- 13. 如何使用連續值[`seaborn`調色板?]顏色`matplotlib` scatterplot
- 14. ImageMagick更改使用C#替換調色板上的顏色#
- 15. 使用PHP/GD創建混合顏色調色板
- 16. AdvancedDataGrid排序數字顏色
- 17. R:排序barplot顏色
- 18. mongodb商店和按顏色排序
- 19. R中定義調色板顏色順序Plotly
- 20. vte_terminal_set_colors調色板的顏色順序是什麼?
- 21. javascript getElementById樣式顏色不適用於非網頁調色板顏色
- 22. 排顏色data.frame
- 23. CKEditor:文本顏色和背景顏色可以使用不同的調色板嗎?
- 24. Gnuplot:控制「設置調色板」的顏色和範圍。
- 25. R:減少調色板的顏色飽和度
- 26. Android:使用色調,飽和度和亮度定義顏色
- 27. Delphi DirectX 32位顏色
- 28. 從真彩色圖像轉換爲調色板顏色
- 29. WPF:重置顏色以使用模板顏色
- 30. Gnuplot - 顯示調色板調色板並設置打印 - 不打印消息「顏色調色板x離散顏色保存到
+1我只是把這些寫功能useit!即使我自己不使用它們,我也知道它們存在! – 2011-04-21 00:45:22
+1。太好了!我從未注意到這個功能。它是什麼時候添加的(或者它一直在那裏)? – 2011-04-21 00:46:49
@Andreas,幾個月前,我發現了這個功能,而我寫了一個應用程序來改變一些顏色的HUE。只是我想知道爲什麼你更喜歡編寫你自己的函數而不使用它?是因爲表現? – RRUZ 2011-04-21 00:50:22