Link to home
Start Free TrialLog in
Avatar of kouroshparsa
kouroshparsaFlag for Canada

asked on

HSB to RGB conversion

I want a code to convert HSB to RGB color system in vb net.
H=hue
S=saturation
B=brightness

I've tried various codes which were online (in various languages)
None of them work! so please only post a solution that works.
Thanks
Avatar of ERobishaw
ERobishaw

Try: http://www.vbaccelerator.com/home/NET/Code/Libraries/Graphics/HLS_to_RGB/article.asp

(HLS = HSB)
Hue = Hue
L [uminence] = B[rightness]
S [aturation] = Saturation

ASKER CERTIFIED SOLUTION
Avatar of ERobishaw
ERobishaw

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of kouroshparsa

ASKER

Thanks for the reply.
I get errors. I fixed some of them but there are still errors saying that the methods need to return a value:
for example, see the blocks of code in the attached code.
How to fix it?

If I can get this to work, I can translate it to vb net.

        public HSB_RGB(Color c)
        {
            red = c.R;
            green = c.G;
            blue = c.B;
            ToHLS();
        }
 
        public HSB_RGB(float hue, float luminance, float saturation)
        {
            this.hue = hue;
            this.luminance = luminance;
            this.saturation = saturation;
            ToRGB();
        }
 
        public HSB_RGB(byte red, byte green, byte blue)
        {
            this.red = red;
            this.green = green;
            this.blue = blue;
        }

Open in new window

These are constructors in C#, the equivalent in VB to the "New" Keyword. So you want something like:


Public Sub New (Color c)
 red = c.R
 ...
 
End Sub
 
Then to use this you go:
 
Dim MyHSB_RGB As New HSB_RGB(Color.Brown)
lumins = MyHSB_RGB.Luminescence 

Open in new window

Yes, it compiles. Thanks ERobishaw.
I noticed that my values are not HSB values; they're HLS values.
Still, for my application it's very good.
though does anyone also know the HSB which i initially was looking for?