我不知道如果这个线程/问题仍然是有效的,但我也一直在寻找一些方法为一种颜色转换为ACI上互联网,但失败了。在我的情况下,我需要一种方法,最好避免外部库和CAD功能。
我无法帮助C#。我通常与Lazarus/Free Pascal一起工作,经过大量试用后,我找到了一个似乎对我来说工作得很好的函数。所以我在这里发布我的代码,以防他们对您或其他人有所帮助。
我的代码如下:
Function RGB2ACIDXFColor(MyColor : TColor) : Integer ;
Var
OldCol, LowR, MidR, HiR : String ;
RCol, GCol, BCol, LowCol, MidCol, HiCol : Integer ;
StPt, HRatio, VRatio, Hemis : Integer ;
Begin
Result := 10 ;
{Break Color Component (BGR Color)}
{IntToHex & Hex2Dec are functions from Lazarus Libraries}
OldCol := IntToHex(MyColor,6) ;
BCol := Hex2Dec(Copy(OldCol,1,2)) ;
GCol := Hex2Dec(Copy(OldCol,3,2)) ;
RCol := Hex2Dec(Copy(OldCol,5,2)) ;
{Find Color Component Priorities}
LowCol := RCol ;
LowR := 'R' ;
If (GCol < LowCol) Then
Begin
LowCol := GCol ;
LowR := 'G' ;
End; //If
If (BCol < LowCol) Then
Begin
LowCol := BCol ;
LowR := 'B' ;
End; //If
HiCol := RCol ;
HiR := 'R' ;
If (GCol > HiCol) Then
Begin
HiCol := GCol ;
HiR := 'G' ;
End; //If
If (BCol > HiCol) Then
Begin
HiCol := BCol ;
HiR := 'B' ;
End; //If
MidCol := GCol ;
MidR := 'G' ;
If ((HiR = 'G') AND (LowR = 'R')) OR
((HiR = 'R') AND (LowR = 'G')) Then
Begin
MidCol := BCol ;
MidR := 'B' ;
End; //If
If ((HiR = 'G') AND (LowR = 'B')) OR
((HiR = 'B') AND (LowR = 'G')) Then
Begin
MidCol := RCol ;
MidR := 'R' ;
End; //If
{Refer to CAD color table}
{Find Color Row}
VRatio := Round((5 * (255 - HiCol))/255) ;
VRatio *= 2 ;
{Find Color Hemisphere}
If (LowCol = 0) Then Hemis := 0 Else Hemis := 1 ;
{Find Color Start Column And Incrementation}
If (LowR = 'B') Then
Begin
HRatio := Round((8 * GCol)/(GCol + RCol)) ;
Result := 10 ;
End; //If
If (LowR = 'G') Then
Begin
HRatio := Round((8 * RCol)/(RCol + BCol)) ;
Result := 170 ;
End; //If
If (LowR = 'R') Then
Begin
HRatio := Round((8 * BCol)/(BCol + GCol)) ;
Result := 90 ;
End; //If
HRatio *= 10 ;
Result += HRatio + VRatio + Hemis ;
If (Result > 249) Then Result -= 240 ;
End; //Sub
我相信你将能够翻译成C#,并希望这将是有用的人。
干杯,
J-埃里克J.