Click here to Skip to main content
15,897,166 members
Home / Discussions / C#
   

C#

 
GeneralRe: Convert color from RGB to Color name Pin
Luc Pattyn14-Oct-10 2:33
sitebuilderLuc Pattyn14-Oct-10 2:33 
GeneralRe: Convert color from RGB to Color name Pin
OriginalGriff14-Oct-10 3:46
mveOriginalGriff14-Oct-10 3:46 
AnswerRe: Convert color from RGB to Color name Pin
Keith Barrow14-Oct-10 1:56
professionalKeith Barrow14-Oct-10 1:56 
AnswerRe: Convert color from RGB to Color name Pin
PIEBALDconsult14-Oct-10 3:09
mvePIEBALDconsult14-Oct-10 3:09 
QuestionRe: Convert color from RGB to Color name Pin
Luc Pattyn14-Oct-10 3:33
sitebuilderLuc Pattyn14-Oct-10 3:33 
AnswerRe: Convert color from RGB to Color name Pin
PIEBALDconsult14-Oct-10 3:41
mvePIEBALDconsult14-Oct-10 3:41 
GeneralRe: Convert color from RGB to Color name Pin
Luc Pattyn14-Oct-10 3:59
sitebuilderLuc Pattyn14-Oct-10 3:59 
AnswerRe: Convert color from RGB to Color name Pin
W Balboos, GHB14-Oct-10 9:38
W Balboos, GHB14-Oct-10 9:38 
A quick and accurate solution for colors that actually have names:

Consider your color fields as a long (32 bit) unsigned int.


i.e., RGB(16,32,64) are actually the values (for three) of bytes.
Convert them so that each takes it's proper place in the long.
Find the value of the long for each of the named colors.
[How you decide to do this I leave as an exercise]

Then, create a switch with each of the known values as a case.
A default value catches the rest (convert to a sting "#rrggbb", for example)
Since this is C#, you can also do the reverse.

Other solution could involve you with the Color enum's.
Loads of ways to do this.

They can be built into a set of overloaded functions so you can make it even easier to convert from the RGB values to string and enum values.

Think of this as a viable (if not always the most efficient) pattern for many similar problems.








"The difference between genius and stupidity is that genius has its limits." - Albert Einstein
"As far as we know, our computer has never had an undetected error." - Weisert
"If you are searching for perfection in others, then you seek dissappointment. If you are searching for perfection in yourself, then you seek failure." - Balboos HaGadol Mar 2010

GeneralRe: Convert color from RGB to Color name Pin
Keith Barrow14-Oct-10 13:00
professionalKeith Barrow14-Oct-10 13:00 
GeneralRe: Convert color from RGB to Color name Pin
PIEBALDconsult14-Oct-10 16:49
mvePIEBALDconsult14-Oct-10 16:49 
GeneralRe: Convert color from RGB to Color name Pin
W Balboos, GHB15-Oct-10 4:46
W Balboos, GHB15-Oct-10 4:46 
GeneralRe: Convert color from RGB to Color name Pin
W Balboos, GHB15-Oct-10 4:35
W Balboos, GHB15-Oct-10 4:35 
GeneralRe: Convert color from RGB to Color name Pin
Keith Barrow16-Oct-10 3:40
professionalKeith Barrow16-Oct-10 3:40 
QuestionMEF never calls OnImportsSatisfied Pin
WebMaster13-Oct-10 23:49
WebMaster13-Oct-10 23:49 
AnswerRe: MEF never calls OnImportsSatisfied Pin
Not Active14-Oct-10 0:13
mentorNot Active14-Oct-10 0:13 
GeneralRe: MEF never calls OnImportsSatisfied Pin
WebMaster14-Oct-10 2:38
WebMaster14-Oct-10 2:38 
GeneralRe: MEF never calls OnImportsSatisfied Pin
Not Active14-Oct-10 3:16
mentorNot Active14-Oct-10 3:16 
QuestionI Used BulkCopy to transfer data One to another DB, moreover i like to know any other mathods... Pin
Manish_Kumar_Nayak13-Oct-10 23:43
Manish_Kumar_Nayak13-Oct-10 23:43 
AnswerRe: I Used BulkCopy to transfer data One to another DB, moreover i like to know any other mathods... Pin
PIEBALDconsult14-Oct-10 3:13
mvePIEBALDconsult14-Oct-10 3:13 
QuestionUnwanted relation: variable-object Pin
memk113-Oct-10 21:34
memk113-Oct-10 21:34 
AnswerRe: Unwanted relation: variable-object Pin
Sauro Viti13-Oct-10 21:46
professionalSauro Viti13-Oct-10 21:46 
GeneralRe: Unwanted relation: variable-object Pin
memk114-Oct-10 10:21
memk114-Oct-10 10:21 
QuestionMemory Leak using Flash.... Pin
jbradshaw13-Oct-10 8:59
jbradshaw13-Oct-10 8:59 
AnswerRe: Memory Leak using Flash.... Pin
Pete O'Hanlon13-Oct-10 9:46
mvePete O'Hanlon13-Oct-10 9:46 
GeneralRe: Memory Leak using Flash.... Pin
jbradshaw13-Oct-10 10:32
jbradshaw13-Oct-10 10:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.