.NET
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Problems with RGB and Color Index
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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?
Re: Problems with RGB and Color Index
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
-------------------------------------------------------------------------
Re: Problems with RGB and Color Index
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Problems with RGB and Color Index
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
[CommandMethod("TestACI")]
public void TestACI()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Edit or;
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-color
Re: Problems with RGB and Color Index
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
Re: Problems with RGB and Color Index
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
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
-------------------------------------------------------------------------



