|
Setting and getting the RGB values of an entity’s color using ObjectARX?使用 ObjectARX 设置并获取实体颜色的 RGB 值?
[code]void asdkGetColor()
{
Adesk::UInt8 blue, green, red;
AcCmColor colors;
// set the color method
Acad::ErrorStatus es =
colors.setColorMethod(AcCmEntityColor::kByColor);
// ok, lets try and set the color using setRGB and setColor
es = colors.setRGB(3, 2, 1); // nValue is an RGB value
// get the RGB value as an Adesk::Int32
Adesk::Int32 nValue = colors.color();
// now convert back to the original values, first 8 bits blue
blue = nValue;
// now move nValue right 8 bits, green
nValue = nValue>>8;
// now get the green
green = nValue;
// move right to the next 8 bits red
nValue = nValue>>8;
red = nValue;
// should be red = 3, green = 2, blue = 1 :-)
{
// lets try the other way
AcCmColor colors;
Acad::ErrorStatus es =
colors.setColorMethod(AcCmEntityColor::kByColor);
// simply get the value with no colours
// set, only the color method bits
Adesk::Int32 nValue = colors.color();
// now set up the colours from our previous values
Adesk::Int8 *ptr =
reinterpret_cast<Adesk::Int8 *> (&nValue);
// now reconstruct
*(ptr) = blue;
*(ptr+1) = green;
*(ptr+2) = red;
// now we can try setColor
es = colors.setColor(nValue);
}
// all works
}[/code] |
|