By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,264 Members | 1,318 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,264 IT Pros & Developers. It's quick & easy.

How would I change the Hue of a bitmap?

P: n/a
Does anyone know how I would change the Hue of a bitmap I have? I tried
looking for a class that would help me, but all I can find is methods that
retrieve Hue values and not change them..
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies

P: n/a


Thank you for using MSDN Newsgroup! My name is Jeffrey, and I will be
assisting you on this issue.
Actually, I did not fully understand what does "the Hue of a bitmap" mean.
Can you show me exactly what you want to do?
Based on my understanding, you want to specify a hue value for the bitmap
point and then change the point hue to your specified value.(Because every
point in the bitmap has a RGB color value associated with it). If I
misunderstand you, please feel free to point out.

Actually, there are 2 color space representation of color choices in
Windows: Red/Green/Blue (RGB) and Hue/Saturation/Luminosity (HSL).
After you specify the HSL value, you should convert it into RGB value
change the bitmap point's RGB value.

In the source code of the article below, ColorHandler.HSVtoRGB method(In
ColorHandler.cs file) provide the algorithm of convert HSL to RGB:

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Hope you have a nice experience on Microsoft Newsgroup!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2

P: n/a

Oh, I have cut out the ColorHandler.HSVtoRGB method for you:

public static RGB HSVtoRGB(HSV HSV)
// HSV contains values scaled as in the color wheel:
// that is, all from 0 to 255.

// for ( this code to work, HSV.Hue needs
// to be scaled from 0 to 360 (it//s the angle of the selected
// point within the circle). HSV.Saturation and HSV.value must be
// scaled to be between 0 and 1.

double h;
double s;
double v;

double r = 0;
double g = 0;
double b = 0;

// Scale Hue to be between 0 and 360. Saturation
// and value scale to be between 0 and 1.
h = ((double) HSV.Hue / 255 * 360) % 360;
s = (double) HSV.Saturation / 255;
v = (double) HSV.value / 255;

if ( s == 0 )
// If s is 0, all colors are the same.
// This is some flavor of gray.
r = v;
g = v;
b = v;
double p;
double q;
double t;

double fractionalSector;
int sectorNumber;
double sectorPos;

// The color wheel consists of 6 sectors.
// Figure out which sector you//re in.
sectorPos = h / 60;
sectorNumber = (int)(Math.Floor(sectorPos));

// get the fractional part of the sector.
// That is, how many degrees into the sector
// are you?
fractionalSector = sectorPos - sectorNumber;

// Calculate values for the three axes
// of the color.
p = v * (1 - s);
q = v * (1 - (s * fractionalSector));
t = v * (1 - (s * (1 - fractionalSector)));

// Assign the fractional colors to r, g, and b
// based on the sector the angle is in.
switch (sectorNumber)
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;
// return an RGB structure, with values scaled
// to be between 0 and 255.
return new RGB((int)(r * 255), (int)(g * 255), (int)(b * 255));

Hope it helps you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! -
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3

P: n/a
v-***** ("Jeffrey Tan[MSFT]") wrote in

Thank you for promptly responding. Actually what I wanted to do was take an
image like a .BMP or .JPG etc. and change its hue value across the entire
picture, just as a program like photoshop would do. I have heard this can
be done in C++ using a ColorMatrix, I believe this is also available to C#
however it seems quite complicated to use and uses several numbers to which
I have no idea what they represent. If you could explain to me how
Colormatrix works and what would need to be done to change the hue value
over the entire image that would be great :) *cough*or an easy to use
class*cough* :).
Nov 15 '05 #4

P: n/a

RGB colorspace to HSV (Hue,Saturation,Value) colorspace is a non-linear
transformation, and unfortunately, the ColorMatrix is strictly linear. The
simple answer is that System.Drawing (GDI+) cannot do this. However, there
are a couple of options...

1 - You could lock the pixels of the bitmap, and do the RGB -> HSV
conversion mathematically. There is a good algorithm in "Computer
Graphics: Principles and Practice" by Foley, vanDam, et al. for converting
between RGB and HSV. You could then change the hue, then convert back to


2 - You can approximate a change of hue by implementing a "tinting" effect.
For example, the following matrix transofms the colors to various shades
of pink...

ColorMatrix pinkMatrix = {(REAL).33, .25, .25, 0, 0,
(REAL).33, .25, .25, 0, 0,
(REAL).33, .25, .25, 0, 0,
0, 0, 0, 1, 0,
0, 0, 0, 0, 1};

This is however a simple linear transformation and is not the same as
changing the image in the HSV color space. If a true Hue change is needed,
option #1 is the only choice.

Hope that helps.

Microsoft Developer Support
Get Secure! -
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.