Entity Color

Hi, I’m learning Aspose.Cad for Java. Can you tell me how to get the entity color(RGB)? And, What does ColorID 0, 7 and 256 mean?

@wlfei0502,
Hello.
Typically DWG/DXF drawings store the index of the color (ACI), table of which you may find e.g. here. 0 means ByBlock, so the color is stored in the block, that contains this entity. 256 means ByLayer, so the color is stored in the layer, assigned to this entity. Color 7 means white, but may be changed to black dependently on the background.
Drawing may store RGB colors too, in this case ColorValue (not ColorId) is used and HasValue inside it may be used to check whether ColorValue contains some number.

Thanks for your reply. I get it. But I have another question, if ColorValue contains some number, how to get RGB value by it?

@wlfei0502,
you can do:

int color = entity.getColorValue();

int b = (color)&0xFF;
int g = (color>>8)&0xFF;
int r = (color>>16)&0xFF;

or just

java.awt.Color c = new java.awt.Color(color);
System.out.println(“co.r=” + c.getRed());
System.out.println(“co.g=” + c.getGreen());
System.out.println(“co.b=” + c.getBlue());

Hello.
I have question,
int color = entity.getColorValue();
above, color is null,is there other ways to get rgb value?

@PSY,
Hello,
please look at entity.getColorId().

@oleksii.gorokhovatskyi Thanks for your reply. I get it. But I have another question,
entity.getColorId() is 256;
image.getLayers().getLayer(entity.getLayerName()).getColorId() is 254 not true color
image.png (4.2 KB)

@PSY,
does getColorValue for this layer store the required color value?

@oleksii.gorokhovatskyi Class CadLayerTable has getColorId method,but the class doesn’t have getColorValue method

@PSY,
could you please attach test file with this layer here, we will look at it.

@oleksii.gorokhovatskyi This my test file test.zip (10.2 KB)

@PSY,
thank you.
Please try to use cadLayerTable.getAttribute420() and decompose it to R, G and B. If this value is not set - ColorID should be used.