Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Routines for converting colours from RGB to HSL an...
Author:
Andrew Gray
Website:
http://www.andrewgray.com
Submitted:
8/25/2001
Version:
VB4
Compatibility:
VB4, VB5, VB6
Category:
Graphics
Views:
12497
Routines for converting colours from RGB to HSL and vice versa.
Declarations:
'none
Code:
Public Sub RGBtoHSL(ByVal Red As Integer, ByVal Green As Integer, ByVal Blue As Integer, ByRef Hue As Integer, ByRef Saturation As Integer, ByRef Luminance As Integer) pRed! = Red / 255 pGreen! = Green / 255 pBlue! = Blue / 255 If pRed! > pGreen! Then If pRed! > pBlue! Then pMax! = pRed! Else pMax! = pBlue! End If ElseIf pGreen! > pBlue! Then pMax! = pGreen! Else pMax! = pBlue! End If If pRed! < pGreen! Then If pRed! < pBlue! Then pMin! = pRed! Else pMin! = pBlue! End If ElseIf pGreen! < pBlue! Then pMin! = pGreen! Else pMin! = pBlue! End If pLum! = (pMax! + pMin!) / 2 If pMax! = pMin! Then pSat! = 0 pHue! = 0 Else If pLum! < 0.5 Then pSat! = (pMax! - pMin!) / (pMax! + pMin!) Else pSat! = (pMax! - pMin!) / (2 - pMax! - pMin!) End If Select Case pMax! Case pRed!: pHue! = (pGreen! - pBlue!) / (pMax! - pMin!) Case pGreen!: pHue! = 2 + (pBlue! - pRed!) / (pMax! - pMin!) Case pBlue!: pHue! = 4 + (pRed! - pGreen!) / (pMax! - pMin!) End Select End If Hue = pHue! * 239 \ 6 If Hue < 0 Then Hue = Hue + 240 Saturation = Int(pSat! * 239) Luminance = Int(pLum! * 239) End Sub Public Sub HSLtoRGB(ByVal Hue As Integer, ByVal Saturation As Integer, ByVal Luminance As Integer, ByRef Red As Integer, ByRef Green As Integer, ByRef Blue As Integer) ReDim temp3!(0 To 2) pHue! = Hue / 239 pSat! = Saturation / 239 pLum! = Luminance / 239 If pSat! = 0 Then pRed! = pLum! pGreen! = pLum! pBlue! = pLum! Else If pLum! < 0.5 Then temp2! = pLum! * (1 + pSat!) Else temp2! = pLum! + pSat! - pLum! * pSat! End If temp1! = 2 * pLum! - temp2! temp3!(0) = pHue! + 1 / 3 temp3!(1) = pHue! temp3!(2) = pHue! - 1 / 3 For n% = 0 To 2 If temp3!(n%) < 0 Then temp3!(n%) = temp3!(n%) + 1 If temp3!(n%) > 1 Then temp3!(n%) = temp3!(n%) - 1 If 6 * temp3!(n%) < 1 Then temp3!(n%) = temp1! + (temp2! - temp1!) * 6 * temp3!(n%) Else If 2 * temp3!(n%) < 1 Then temp3!(n%) = temp2! Else If 3 * temp3!(n%) < 2 Then temp3!(n%) = temp1! + (temp2! - temp1!) * ((2 / 3) - temp3!(n%)) * 6 Else temp3!(n%) = temp1! End If End If End If Next n% pRed! = temp3!(0) pGreen! = temp3!(1) pBlue! = temp3!(2) End If Red = Int(pRed! * 255) Green = Int(pGreen! * 255) Blue = Int(pBlue! * 255) End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2024 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement