.NET

Reply
Valued Contributor
82 Posts
0 Kudos
Registered: ‎06-26-2008
Post 1 of 6

Problems with RGB and Color Index

717 Views, 5 Replies
11-29-2012 04:47 AM

AutoCAD 2013:

The RGB values for Colour 36 are 76,38,0

 

BUT

 

If I do a color.fromRGB(76,38,0) the color i get back has colorIndex 38 (which according to the color picker in AutoCAD is 38,19,0.

 

Am I being stupid or is this just wrong?

*Expert Elite*
9,815 Posts
1,211 Kudos
Registered: ‎06-29-2007
Post 2 of 6

Re: Problems with RGB and Color Index

11-30-2012 02:52 AM in reply to: Paulio

Hi,

 

>> The RGB values for Colour 36 are 76,38,0

Where do you have that info from? Just to get not to complex in this discussion but try to use AutoCAD with black background and then with white background. If my brain works ok: Some years ago there was a discussion that RGB values (not just white and grey) changes with the color of the background.

 

Can you describe what your goal is, what you want to get done?

We may then have ideas on what to do or how to go on.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Valued Contributor
82 Posts
0 Kudos
Registered: ‎06-26-2008
Post 3 of 6

Re: Problems with RGB and Color Index

11-30-2012 03:50 AM in reply to: Alfred.NESWADBA

Hi Alfred,

 

The RGB values come from the colour picker in AutoCAD. When I hover the mouse over colour index 36 it displays the RGBs as 76,38,0.

 

As I said, the colour I get back from Color.FromRGB(76,38,0) has a colour index of 38. I've tried it with a few other RGB values that I've taken from the colour picker. The RGBs for colour index 42 (165,124,0) give me a colour with index 44. The RGBs for colour index 44(127,95,0) give me a colour with index 46. It seemed to be giving me back a colour with the index of the next colour up on the adjacent row in the colour picker grid. So, I thought I'd see what happened if I tried colour index 38 which is on the top row. The index I got back from the RGBs for 38 (38,19,0) is 28!

 

The problem I have is that if I am identifying polylines for example, by their RGB values, and I use the colour index, I can't go from RGB to ColourIndex and back to the same RGBs.

 

It's actually going:

Col1 = Color.FromRGB(76,38,0) 

(Col1.ColourIndex is then 38)

Polyline.Color = Col1

Col2 = Color.FromColorIndex(Polyline.ColorIndex)

Col2.R is then 38

Col2.G is then 19

Col2.B is then 0)

 

The reason for trying to use the index was that our customer wanted to plot monochrome and setting a polyline colour to a colour that's been retrieved using RGB values, means that it still plots in colour even though it does have colour index within the 0-255 range. That's how I discovered the issue.

 

I'm working around it by using the colour indexes (indices?) from the start so if I want a polyline that represents 'Area A' I set its colourIndex to 36 and then when I programmatically try to determine what the polyline is defining, I look again at its colour index which is 36 (obviously) which I then look up in my database to get back the value 'Area A'

 

Sorry forgot to say, I've tried different background colours and it makes no difference.

 

Thanks

 

Paul

Moderator
1,465 Posts
277 Kudos
Registered: ‎04-09-2008
Post 4 of 6

Re: Problems with RGB and Color Index

11-30-2012 05:00 AM in reply to: Paulio
[CommandMethod("TestACI")]
public void TestACI() 
{
    Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
    Color Col1 = Color.FromRgb(76, 38, 0);
    byte index = EntityColor.LookUpAci(Col1.Red,Col1.Green, Col1.Blue);
    ed.WriteMessage("\nAci index = {0}", index);
    int rgb = EntityColor.LookUpRgb(index);
    System.Drawing.Color Col2 = System.Drawing.Color.FromArgb(rgb);
    ed.WriteMessage("\nColor Red={0}, Green={1}, Blue={2}", 
Col2.R, Col2.G, Col2.B); }

 Also this link can be useful: http://forums.autodesk.com/t5/NET/Converting-colors/td-p/1957097


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Valued Contributor
82 Posts
0 Kudos
Registered: ‎06-26-2008
Post 5 of 6

Re: Problems with RGB and Color Index

11-30-2012 06:51 AM in reply to: Alexander.Rivilis

Hi Alexander,

 

I think you might have misunderstood what I was trying to do but no matter. I didn't know about the EntityColor.LookupACI so thanks for that.

 

I have to apologise to Alfred. Changing the background colour does indeed affect the colour palette. I had my background colour set to 40,40,40 which is why when I changed it to white I didn't see any change.

It seems that 31,31,31 is the tipping point. Under that and the colour palette displays the correct RGBs against the indexes. Anything over that and the palette is shifted.

 

Not sure I really understand why it shifts but at least I know now and I can code for it in future.

 

Thanks

*Expert Elite*
9,815 Posts
1,211 Kudos
Registered: ‎06-29-2007
Post 6 of 6

Re: Problems with RGB and Color Index

11-30-2012 08:05 AM in reply to: Paulio

Hi,

 

>> I have to apologise to Alfred

No, you don't have to apologize for anything. I also don't see the logic behind the differences depending on background (well, I understand the inverting grey's, ok), it was just remembering to a thread long ago.

 

- alfred -

-------------------------------------------------------------------------
Alfred NESWADBA
Ingenieur Studio HOLLAUS ... www.hollaus.at
-------------------------------------------------------------------------
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are you interested in helping shape the future of the Autodesk Community? To participate in this brief usability study, please click here. Your time and input is greatly appreciated!