我想在我的表格上有一个跟踪栏,它对应于背景颜色的HUE,给定范围为1到360,另一个跟踪条对应于背景颜色的饱和度,范围为1到50.
答案 0 :(得分:2)
使用找到here的HSVtoRGB
程序,您可以将TrackBar
控件挂钩到同一个事件处理程序并使用此代码:
Private Sub tbHUE_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tbHUE.Scroll, tbSaturation.Scroll
Dim r, g, b As Integer
HSVtoRGB(r, g, b, tbHUE.Value, tbSaturation.Value / 50, 255)
BackColor = Color.FromArgb(r, g, b)
End Sub
编辑:以下是更正的程序,因为链接中的程序并不真正遵循最佳做法:
Private Sub HSVtoRGB(ByRef Red As Integer, ByRef Green As Integer, ByRef Blue As Integer, ByVal Hue As Double, ByVal Sat As Double, ByVal Value As Integer)
Dim i As Integer
Dim f As Double, p As Double, q As Double, t As Double
If Sat = 0 Then
Red = Value
Green = Value
Blue = Value
Exit Sub
End If
i = CInt(Hue) \ 60
Hue = Hue / 60
f = Hue - i
p = Value * (1 - Sat)
q = Value * (1 - Sat * f)
t = Value * (1 - Sat * (1 - f))
Select Case i
Case 0
Red = Value
Green = CInt(t)
Blue = CInt(p)
Case 1
Red = CInt(q)
Green = Value
Blue = CInt(p)
Case 2
Red = CInt(p)
Green = Value
Blue = CInt(t)
Case 3
Red = CInt(p)
Green = CInt(q)
Blue = Value
Case 4
Red = CInt(t)
Green = CInt(p)
Blue = Value
Case 5
Red = Value
Green = CInt(p)
Blue = CInt(q)
End Select
End Sub
答案 1 :(得分:1)
Julien有一个很好的答案,但这会出现在搜索中,所以很多链接总是有帮助: - )
Bob Powell在他的RGB and HSL Colour Space Conversions中也有一些HSL代码。
而且,(这个人在c#中可能不会那么帮助),克里斯杰克逊有一些看起来合理的HSB code。链接的vb.net端口是,嗯,notsogood,它有选项严格打开的问题。不是不可克服的,但也不准备复制品