|
使用 ObjectARX 获取实体的 RGB 颜色
问题
有没有办法获取实体的 RGB 颜色?color() 函数返回一个 AcCmColor 对象。您如何从中获取 RGB 值?
溶液
有几种方法可以将颜色应用于实体。如果实体使用的是颜色索引 (ACI),则可以使用 acedGetRgb() 来获取 RGB vaules。下面是一个示例,该示例获取颜色方法并显示使用 ACI 或"真彩色"的实体的 RGB 值。如果实体使用的是 byLayer,则必须访问图层才能获取颜色信息。
[code]static void ASDKwb_test(void)
{
ads_name eName;
ads_point pnt1;
// select the entity to extract the color
int res = acedEntSel(_T("\nselect an entity"), eName, pnt1);
// if ok
if (res == RTNORM)
{
AcDbObjectId oId;
// convert the ename to an object id
acdbGetObjectId(oId, eName);
// open for read
AcDbObjectPointer<AcDbEntity> pEnt(oId, AcDb::kForRead);
// if ok
if (pEnt.openStatus() == Acad::eOk)
{
// get the color
AcCmColor color = pEnt->color();
Adesk::UInt8 blue, green, red;
Adesk::UInt16 ACIindex;
long acirgb, r,g,b;
// get the RGB value as an Adesk::Int32
Adesk::Int32 nValue = color.color();
// now extract the values
AcCmEntityColor::ColorMethod cMethod;
cMethod = color.colorMethod();
switch(cMethod)
{
case AcCmEntityColor::kByColor :
// now convert back to the original values, first 8 bits blue
acutPrintf(_T("\nEntity using True Color"));
blue = nValue;
acutPrintf(_T("\nblue value = %i"), blue);
// now move nValue right 8 bits, green
nValue = nValue>>8;
// now get the green
green = nValue;
acutPrintf(_T("\ngreen value = %i"), green);
// move right to the next 8 bits red
nValue = nValue>>8;
red = nValue;
acutPrintf(_T("\nred value = %i"), red);
break;
case AcCmEntityColor::kByACI :
ACIindex = color.colorIndex();
acutPrintf(_T("\nEntity using ACI, number: %i", ACIindex));
acirgb = acedGetRGB ( ACIindex );
r = ( acirgb & 0xffL );
acutPrintf(_T("\nred value = %i"), r);
g = ( acirgb & 0xff00L ) >> 8;
acutPrintf(L"\ngreen value = %i"), g);
b = acirgb >> 16;
acutPrintf(L"\nblue value = %i"), b);
break;
case AcCmEntityColor::kByLayer :
acutPrintf(_T("\nEntity Color is by layer"));
break;
default :
acutPrintf(_T("\nEntity not using ACI, byLayer or ByColor"));
break;
}
}
}
}
[/code] |
|