Color Conversions (RGB, CMYK, HSB) 
Author Message
 Color Conversions (RGB, CMYK, HSB)

In one of my projects, I wanted to allow the user to select colors using
CMYK, RGB, or HSB coding schemes. I've found the code to convert CMYK
colors to RGB, but I can't seem to find ANYTHING about HSB (aka HLS or
HSV). Obviously, there is *some* way to convert HSB to RGB, because the VB
color palette lets you specify colors in hue, saturation and brightness.

So here are my questions:

1. Is there a way to convert RGB colors to CMYK? If so, does anyone know
the algorithm?

2. Is there a way to convert HSB values to RGB? If so, does anyone know the
algorithm?

Any help you can provide will be greatly appreciated.

P.S. For those interested, here's the code to convert CMYK to RGB:

Option Explicit

Function GetRGBFromCMYK(ByVal c As Byte, _
                        ByVal m As Byte, _
                        ByVal y As Byte, _
                        ByVal k As Byte) _
                        As Long

   '// Returns the RGB equivalent of the specified CMYK color.
   '// c, m, y, k must be from 1 to 100

   Assert c >= 0 And c <= 100
   Assert m >= 0 And m <= 100
   Assert y >= 0 And y <= 100

   Dim chRed As Byte
   Dim chGreen As Byte
   Dim chBlue As Byte
   Dim rgbValue As Long

   chRed = ExtractColor(c, k)
   chGreen = ExtractColor(m, k)
   chBlue = ExtractColor(y, k)

   rgbValue = rgb(chRed, chGreen, chBlue)

   GetRGBFromCMYK = rgbValue

End Function

Function Max(v1 As Variant, v2 As Variant) As Variant

   '// Returns the greater of two values.

   Min = IIf(v1 > v2, v1, v2)

End Function

Function Min(v1 As Variant, v2 As Variant) As Variant

   '// Returns the lesser of two values.

   Min = IIf(v1 < v2, v1, v2)

End Function

Function ExtractColor(chColor As Byte, chBlack As Byte) As Byte

   '// Extracts an RGB color component from a CMYK color.

   Dim ch As Byte

   ch = (100 - chColor) - chBlack
   ch = Min(ch, 255)
   ch = ch * 2.56
   ch = Max(ch, 0)

   ExtractColor = ch

End Function

--
Michael A. Hofer



Sat, 23 Jan 1999 03:00:00 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. convert HSB color to RGB, please help

2. Colors RGB to CMYK, HSL, ...

3. cmyk vs rgb (colors/colours) Quark, quark.

4. Color Conversions (Hue/Lum/Saturation) to RGB

5. 256 Colors to RGB conversion?

6. RGB to CIELAB (or simply lab) color conversion

7. convert HSB to RGB in vb.NET

8. Converting from HSB to RGB

9. RGB to CMYK, HSL ...

10. Converting RGB to CMYK value

11. RGB to CMYK

12. RGB to CMYK, HSL ...

 

 
Powered by phpBB® Forum Software