c语言数组表示rgb色彩,将RGB颜色转换为C中最接近的ACI颜色#

博主分享了一个在Lazarus/FreePascal中实现的颜色转换函数,将RGB颜色转换为ACI颜色,避免使用外部库和CAD功能。函数通过分析颜色分量来确定色相、饱和度和明度,并根据特定规则映射到ACI色表。该代码可以作为C#程序员的参考。
摘要由CSDN通过智能技术生成

我不知道如果这个线程/问题仍然是有效的,但我也一直在寻找一些方法为一种颜色转换为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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值