(I even code in my dreams)

DR00ME

Well-known member
Joined
Feb 6, 2004
Messages
169
Location
Finland
Does Anyone know a better algorithm for changing HSV values to RGB ?


[VB]Public Shared Sub ConvertHSBToRGB(h As Single, s As Single, v As Single, ByRef r As Single, ByRef g As Single, ByRef b As Single)

If s = 0F Then

if s = 0 then h is undefined

r = v

g = v

b = v

Else

Dim hue As Single = System.Convert.ToSingle(h)

If h = 360F Then

hue = 0F

End If

hue /= 60F

Dim i As Integer = Fix(Math.Floor(System.Convert.ToDouble(hue)))

Dim f As Single = hue - i

Dim p As Single = v *(1F - s)

Dim q As Single = v *(1F - s * f)

Dim t As Single = v *(1F - s *(1 - f))



Select Case i

Case 0

r = v

g = t

b = p

Case 1

r = q

g = v

b = p

Case 2

r = p

g = v

b = t

Case 3

r = p

g = q

b = v

Case 4

r = t

g = p

b = v

Case 5

r = v

g = p

b = q



Case Else

r = 0F

g = 0F

b = 0F Trace.Assert(false);

hue out of range

End Select

End If

End Sub ConvertHSBToRGB[/VB]
 
OMG: WINDOWS API Function "ColorHLSToRGB" from "Shlwapi.dll" I think Im gonna dance now tough it is 4:20 am....:D


Private Declare Function ColorHLSToRGB Lib "SHLWAPI.DLL" _
(ByVal wHue As Integer, ByVal wLuminance As Integer, ByVal wSaturation As Integer) As Long


How do I convert this Long to RGB ? I got some weird readings like 567345235234...erm HELP!
 
Last edited by a moderator:
Back
Top