![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | Translating colors to hex and back PowerShell/.NET/COM have anything that can take a 'human readable' color like "red" and convert it to hex, and vice-versa? Marco |
My System Specs![]() |
| | #2 (permalink) |
| | 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 |
My System Specs![]() |
| | #3 (permalink) |
| | Re: Translating colors to hex and back PoSH> [System.Drawing.Color]'red' R : 255 G : 0 B : 0 A : 255 IsKnownColor : True IsEmpty : False IsNamedColor : True IsSystemColor : False Name : Red PoSH> ([System.Drawing.Color]'red' ).ToArgb() -65536 Greetings /\/\o\/\/ "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? > > Marco > |
My System Specs![]() |
| | #4 (permalink) |
| | RE: Translating colors to hex and back just out of curiosity what does red translate to in hex -- Richard Siddaway Please note that all scripts are supplied "as is" and with no warranty Blog: http://richardsiddaway.spaces.live.com/ PowerShell User Group: http://www.get-psuguk.org.uk "Marco Shaw" wrote: > PowerShell/.NET/COM have anything that can take a 'human readable' color > like "red" and convert it to hex, and vice-versa? > > Marco > > > |
My System Specs![]() |
| | #5 (permalink) |
| | Re: Translating colors to hex and back "RichS" <RichS@discussions.microsoft.com> wrote in message news:6E3D0DAE-E819-4CE1-B645-F10B91E5D447@microsoft.com... > just out of curiosity what does red translate to in hex 0xFFFF0000 -- Keith |
My System Specs![]() |
| | #6 (permalink) |
| | Re: Translating colors to hex and back PoSH> $c = [drawing.color]'red' PoSH> "{0:x}" -f $c.ToArgb() ffff0000 ;-) gr /\/\o\/\/ "RichS" <RichS@discussions.microsoft.com> wrote in message news:6E3D0DAE-E819-4CE1-B645-F10B91E5D447@microsoft.com... > just out of curiosity what does red translate to in hex > -- > Richard Siddaway > Please note that all scripts are supplied "as is" and with no warranty > Blog: http://richardsiddaway.spaces.live.com/ > PowerShell User Group: http://www.get-psuguk.org.uk > > > "Marco Shaw" wrote: > >> PowerShell/.NET/COM have anything that can take a 'human readable' color >> like "red" and convert it to hex, and vice-versa? >> >> Marco >> >> >> |
My System Specs![]() |
| | #7 (permalink) |
| | Re: Translating colors to hex and back Ok, but ( curiosity killed the cat ) what is white ? PoSH> [enum]::GetNames([System.ConsoleColor]) |% {$_;"{0:x}" -f ([drawing.Color]$_).ToArgb()} Black ff000000 DarkBlue ff00008b DarkGreen ff006400 DarkCyan ff008b8b DarkRed ff8b0000 DarkMagenta ff8b008b DarkYellow Cannot convert value "DarkYellow" to type "System.Drawing.Color". Error: "DarkYellow is not a valid value for Int32." At line:1 char:77 + [enum]::GetNames([System.ConsoleColor]) |% {$_;"{0:x}" -f ([drawing.Color]$_) <<<< .ToArgb()} Gray ff808080 DarkGray ffa9a9a9 Blue ff0000ff Green ff008000 Cyan ff00ffff Red ffff0000 Magenta ffff00ff Yellow ffffff00 White ffffffff For DarkYellow your on your own , but .. (more than you did want to know ) PoSH> [enum]::GetNames([drawing.KnownColor]) |% {$_;"{0:x}" -f ([drawing.Color]$_).ToArgb()} but got to pack, plane leaves soon ;-) PoSH> [datetime]'Friday, March 09, 2007 01:15 PM' - (get-date) |% {"$_"} 16:05:16.2980055 enjoy, Greetings /\/\o\/\/ "/\/\o\/\/ [MVP]" <mow001@hotmail.NoSpam> wrote in message news:222FDFD3-E735-4B99-9A53-E31E67D4F0B3@microsoft.com... > PoSH> $c = [drawing.color]'red' > PoSH> "{0:x}" -f $c.ToArgb() > ffff0000 > > ;-) > > gr /\/\o\/\/ > > "RichS" <RichS@discussions.microsoft.com> wrote in message > news:6E3D0DAE-E819-4CE1-B645-F10B91E5D447@microsoft.com... >> just out of curiosity what does red translate to in hex >> -- >> Richard Siddaway >> Please note that all scripts are supplied "as is" and with no warranty >> Blog: http://richardsiddaway.spaces.live.com/ >> PowerShell User Group: http://www.get-psuguk.org.uk >> >> >> "Marco Shaw" wrote: >> >>> PowerShell/.NET/COM have anything that can take a 'human readable' color >>> like "red" and convert it to hex, and vice-versa? >>> >>> Marco >>> >>> >>> > |
My System Specs![]() |
| | #8 (permalink) |
| | Re: Translating colors to hex and back In message <222FDFD3-E735-4B99-9A53-E31E67D4F0B3@microsoft.com>, "/\\/\\o\\/\\/ [MVP]" <mow001@hotmail.NoSpam> writes >PoSH> $c = [drawing.color]'red' >PoSH> "{0:x}" -f $c.ToArgb() >ffff0000 > >;-) Thanks VERY much. BTW: where is this format documented? The calling seqence is a bit off, I sort of expected "{0:x} in hex`n{1} in decimal" -f $c.ToArgb() $c.ToArgb() To work. But it generated an error, whereas: I was sort of surprised to find this worked: PSH [D:\foo]: "{0:x} in hex`n{1} in decimal" -f $c.ToArgb(),$c.ToArgb() ffff0000 in hex -65536 in decimal I expected the paramaters to the right of '-f' to be space, not comma delimited. Thomas -- Thomas Lee doctordns@gmail.com MVP - Admin Frameworks and Security |
My System Specs![]() |
| | #9 (permalink) |
| | Re: Translating colors to hex and back "Thomas Lee" <tfl@psp.co.uk> wrote in message news:mKgF6DRjyJ8FFArR@mail.psp.co.uk... > In message <222FDFD3-E735-4B99-9A53-E31E67D4F0B3@microsoft.com>, > "/\\/\\o\\/\\/ [MVP]" <mow001@hotmail.NoSpam> writes >>PoSH> $c = [drawing.color]'red' >>PoSH> "{0:x}" -f $c.ToArgb() >>ffff0000 >> >>;-) > > > Thanks VERY much. > > BTW: where is this format documented? http://msdn2.microsoft.com/en-us/lib...or.toargb.aspx > > The calling seqence is a bit off, I sort of expected > "{0:x} in hex`n{1} in decimal" -f $c.ToArgb() $c.ToArgb() > > To work. But it generated an error, whereas: > > I was sort of surprised to find this worked: > PSH [D:\foo]: "{0:x} in hex`n{1} in decimal" -f $c.ToArgb(),$c.ToArgb() > ffff0000 in hex > -65536 in decimal > > I expected the paramaters to the right of '-f' to be space, not comma > delimited. Yeah I've been bit by that before. I just had to wire it into my memory that -f expects an array arguments. -- Keith |
My System Specs![]() |
| | #10 (permalink) |
| | 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? >> >> Marco /\/\o\/\/, You're not allowed to make fun of my color choices... Chocolate... Really now! |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Translating English to Polish | .NET General | |||
| Translating Japanese to English In a browser | Browsers & Mail | |||
| help translating winrm authendication to powershell | PowerShell | |||
| VISTA feels like going back to the Stone Age (in nice colors) [Edited] | Vista General | |||
| Windows Mail Stationery Stopped Working, Also Font colors and background colors... | Vista mail | |||