我需要HSL
颜色值转换为RGB
,或与Powershell的更精确HSL值到System.Drawing.Color
对象。 在其他程序中有几种解决方案 - 语言在那里(如LINK)。但虽然看起来很简单,但我没有把它转换成Powershell。Powershell的:HSL为RGB
Function HSLtoRGB ($H,$S,$L) {
$H = [double]($H/360)
$S = [double]($S/100)
$L = [double]($L/100)
if ($s -eq 0) {
$r = $g = $b = $l
}
else {
if ($l -lt 0.5){
$q = $l * (1 + $s)
}
else {
$q = $l + $s - $l * $s
}
$p = (2 * $L) - $q
$r = (Hue2rgb $p $q ($h + 1/3))
$g = (Hue2rgb $p $q $h)
$b = (Hue2rgb $p $q ($h - 1/3))
}
$r = [Math]::Round($r * 255)
$g = [Math]::Round($g * 255)
$b = [Math]::Round($b * 255)
return ($r,$g,$b)
}
function Hue2rgb ($p, $q, $t) {
if ($t -lt 0) { $t++ }
if ($t -gt 0) { $t-- }
if ($t -lt 1/6) { return ($p + ($q + $p) * 6 * $t) }
if ($t -lt 1/2) { return $q }
if ($t -lt 2/3) { return ($p + ($q - $p) * (2/3 - $t) * 6) }
return $p
}
HSLtoRGB 63 45 40 # result should be R 145 G 148 B 56
“我没有把它转换成Powershell” - 你到目前为止尝试过什么?它不符合你的期望? –
您链接到的答案中的示例函数在移植到PowerShell btw时工作得很好 –
是的,忘记了代码。 :)我有几条线和一条我根本无法翻译的疑惑(见代码)。主要是我不知道一些运营商的意思。 – Moss