Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

If I run some color processing function, like:

Blend[RGBColor /@ {"#DC4E00", "#000000", "#822250", "#FCC11B"}]

I get back a RGBColor object:

RGBColor[0.5901960784313726, 0.29901960784313725, 0.10490196078431373]

Is there a simple way to convert that RGBColor to an HTML string, like:

"#813912"
share|improve this question
1  
closely related 18495 – Kuba Jan 13 at 20:29
    
Related: stackoverflow.com/q/5637709 – Karsten 7. Jan 13 at 20:53
up vote 11 down vote accepted

Seems like the function I was wanting was:

hexifyColor[color_RGBColor] := 
  StringJoin["#", IntegerString[Round[Level[color, 1]*255], 16, 2]]
share|improve this answer

It is there, deep down, but I'm too lazy to dig...

hexColor = StringCases[
    ExportString[Style[1, #], "HTMLFragment"], 
    "color:" ~~ color__ ~~ "\"" :> color
][[1]] &


hexColor@Blue
"#0000ff" 
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.