Pada Posting sebelumnya telah dibahas mengenai warna rgb dan hsv. di bawah ini adalah formula untuk membalikkan warna hsv ke rgb :
Program :
Public Structure RGB
Dim R As Double
Dim G As Double
Dim B As Double
End Structure
Public Structure HSV
Dim H As Double
Dim S As Double
Dim V As Double
End Structure
Public Function hsv2rgb(ByVal cin As HSV) As RGB
Dim x, c, m As Double ' untuk nilai warna dan mode
Dim _R, _G, _B As Double ' warna aksen
c = cin.V * cin.S
x = c * (1 - Math.Abs(modulusku((cin.H / 60), 2) - 1))
m = cin.V - c
If cin.H >= 0 And cin.H < 60 Then
_R = c : _G = x : _B = 0
ElseIf cin.H >= 60 And cin.H < 120 Then
_R = x : _G = c : _B = 0
ElseIf cin.H >= 120 And cin.H < 180 Then
_R = 0 : _G = c : _B = x
ElseIf cin.H >= 180 And cin.H < 240 Then
_R = 0 : _G = x : _B = c
ElseIf cin.H >= 240 And cin.H < 300 Then
_R = x : _G = 0 : _B = c
ElseIf cin.H >= 300 And cin.H < 360 Then
_R = c : _G = 0 : _B = x
End If
hsv2rgb.R = _R + m
hsv2rgb.G = _G + m
hsv2rgb.B = _B + m
End Function
Post a Comment