14,268,557 members
Rate this:
See more:
I've made a color picker tool that gets a ARGB color from a pixel. I've figured out how to get HTML and HEX colors, but can't figure out how to get HSV or CMYK. All the articles that I've found are in C#. I've tried converting a few(with web converters), but I always run into a problem. Here's the code that I'm using to get the ARGB and HTML colors:

PXL_COLOR = bmp.GetPixel(0, 0).ToString 'ARGB

PXL_HTML = System.Drawing.ColorTranslator.ToHtml(bmp.GetPixel(0, 0)) 'HTML

Posted

Rate this:

## Solution 1

If you have RGB you can calculate the CMYK and HSV values.

Have a look at this link: http://www.rapidtables.com/convert/color/index.htm[^]

Example:
R=50 = 50/255 = 0.196
G=100 = 100/255 = 0.392
B=150 = 150/255 = 0.588

K = 1-max(0.196, 0.392, 0.588) = 0.412
C = (1-0.196-0.412)/(1-0.412) = 0.667
M = (1-0.392-0.412)/(1-0.412) = 0.333
Y = (1-0.588-0.412)/(1-0.412) = 0
v2
fjdiewornncalwe 8-Apr-13 12:27pm

My 5. Good resource.
7774tlas 8-Apr-13 15:08pm

Have patience w/ me, I'm horrible at math. This is what I've got so far, but what should I use in place of "max"? I keep getting an error.

Sub RGBtoCMYK()

Dim R As Double
Dim G As Double
Dim B As Double
Dim C As Double
Dim M As Double
Dim Y As Double
Dim K As Double

R = R / 255
G = G / 255
B = B / 255

K = 1 - max(R, G, B)
C = (1 - R - K) / (1 - K)
M = (1 - G - K) / (1 - K)
Y = (1 - B - K) / (1 - K)

End Sub
Rate this:

## Solution 2

No Problem.

You can use Math.Max but it only accepts 2 values to compare. Max compares multiple values and retuns the largest one.

This should do the trick :)
```Structure CMYK
Dim C As Double
Dim M As Double
Dim Y As Double
Dim K As Double
End Structure

Structure RGB
Dim R As Double
Dim G As Double
Dim B As Double
End Structure

Private Function RGBtoCMYK(ByVal rgbIn As RGB) As CMYK
Dim cmykOut As CMYK
With rgbIn
.R = .R / 255
.G = .G / 255
.B = .B / 255
End With
'math.max only accepts 2 aguments to compare.
'Put all the values in an array and get the .Max of the array
Dim arr(2) As Double
arr(0) = rgbIn.R
arr(1) = rgbIn.G
arr(2) = rgbIn.B

With cmykOut
.K = 1 - arr.Max
.C = (1 - rgbIn.R - .K) / (1 - .K)
.M = (1 - rgbIn.G - .K) / (1 - .K)
.Y = (1 - rgbIn.B - .K) / (1 - .K)
End With
Return cmykOut
End Function```

You can call the funtion usings something like
```Dim colorIn As RGB
With colorIn
.R = 50
.G = 100
.B = 150
End With
Dim colorOut As CMYK = RGBtoCMYK(colorIn)```
7774tlas 9-Apr-13 4:08am

I had not used functions or arrays before this, so not only have you solved my problem, but you also taught me a couple new tricks. Thank you very much for your time and knowledge.
petervanekeren 10-Apr-13 5:55am

You're welcome :)

HSV is another story. Some serious (at least for me) math is needed to calculate that.