|
Re: Translating colors to hex and back "Marco Shaw" <marcoDOTshaw_@_gmailDOTcom> wrote in message news:%23Mz37NaYHHA.2436@TK2MSFTNGP06.phx.gbl...
> PowerShell/.NET/COM have anything that can take a 'human readable' color
> like "red" and convert it to hex, and vice-versa?
>
42# ipasm System.Drawing # from PSCX 1.1
GAC Version Location
--- ------- --------
True v2.0.50727 C:\WINDOWS\assembly\GAC_MSIL\System.Drawing\2.0.0.0__b...
43# [drawing.Color]::FromName('red')
R : 255
G : 0
B : 0
A : 255
IsKnownColor : True
IsEmpty : False
IsNamedColor : True
IsSystemColor : False
Name : Red
44# "0x{0:X}" -f [drawing.Color]::FromName('red').R
0xFF
To go the other way is a bit harder:
57# [Enum]::GetValues([drawing.KnownColor]) | %{$c = [drawing.color]::FromKnownC
olor($_); if ($c.ToArgb() -eq 0xffff0000) { "The color is $_" }}
The color is Red
Note that the hex format is AARRGGBB where AA is the alpha channel and is normally set to FF.
--
Keith |