Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Does Anyone know a better algorithm for changing HSV values to RGB ?

 

 

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

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

Posted (edited)

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!

Edited by DR00ME

"Everything should be made as simple as possible, but not simpler."

"It's not that I'm so smart , it's just that I stay with problems longer ."

- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...