- UID
- 3606
- 积分
- 0
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2002-4-4
- 最后登录
- 1970-1-1
|
发表于 2003-10-24 15:48:59
|
显示全部楼层
Answer
The following two functions will help you translate an RGB value to the nearest
equivalent AutoCAD Color Index. The function goes through all the AutoCAD
colours and searches the nearest one by comparing the differences from the given
RGB values to the RGB values corresponding to the 255 AutoCAD colors.
// This function returns the ACI color which is the "nearest" color to
// the color defined by the red, green and blue (RGB) values passed
// in argument.
int getNearestACI (const long red, const long green, const long blue) {
long acirgb, r,g,b;
long mindst = 2147483647L;
long dst = 0;
int minndx = 0;
for ( int i = 1; i < 255; i++ ) {
acirgb = acdbGetRGB ( i );
r = ( acirgb & 0xffL );
g = ( acirgb & 0xff00L ) >> 8;
b = acirgb >> 16;
dst = abs ( r-red) + abs ( g -green) + abs (b-blue);
if ( dst < mindst ) {
minndx = i;
mindst = dst;
}
}
return minndx;
}
// This function returns the ACI which has the "nearest" color to
// the color defined by rgb paramether of the function
// The rgb parameter is defined as follows:
// The low byte is the red, the next byte is the green, and
// the last byte is the blue RGB value -> 0x00BBGGRR
// The red, green, and blue bytes can have values from 0 to 255.
int getNearestACI (const unsigned long rgb) {
long r = ( rgb & 0xffL );
long g = ( rgb & 0xff00L ) >> 8;
long b = rgb >> 16;;
return getNearestACI (r, g, b);
}
Converting an AutoCAD Color Index (ACI) into its RGB color value can be done
using the ObjectARX function 'extern unsigned long acdbGetRGB(int color);'
Also same can be done by using the 'AcCmEntityColor '. For more information
and various member functions of 'AcCmEntityColor' look at Object Arx online help. |
|