473,397 Members | 1,961 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

How would I change the Hue of a bitmap?

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
4 21455

Hi,

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:
http://msdn.microsoft.com/msdnmag/is...r/default.aspx

==============================================
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! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2

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;
}
else
{
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;
break;

case 1:
r = q;
g = v;
b = p;
break;

case 2:
r = p;
g = v;
b = t;
break;

case 3:
r = p;
g = q;
b = v;
break;

case 4:
r = t;
g = p;
b = v;
break;

case 5:
r = v;
g = p;
b = q;
break;
}
}
// 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! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #3
v-*****@online.microsoft.com ("Jeffrey Tan[MSFT]") wrote in
news:0d*************@cpmsftngxa07.phx.gbl:
http://msdn.microsoft.com/msdnmag/is...cker/default.a
spx


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
Hello,

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
RGB.

or

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.

Regards.,
Dave
Microsoft Developer Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Eric | last post by:
I have written a C# program that creates a new bitmap: Bitmap ChartBitmap = new Bitmap( 780, 360 ); then I create a button which copies that bitmap into the clipboard: ...
2
by: James Dean | last post by:
I create a bitmap like this. The width and height are got from the compressed file i am reading. The width and height are in pixels.....1bpp bitmap = new...
2
by: Sanjeeva Reddy | last post by:
hai Anti Keskinen, i have used the following code MyListView->LargeImageList->ImageSize = gcnew System::Drawing::Size(100, 100); // Sets large image size to 100, 100 here i am getting error...
7
by: Fir5tSight | last post by:
Hi All, I used the following code in C#: using System.Drawing; //blah blah blah Bitmap bmp = new Bitmap();
4
by: joe | last post by:
how to resize an upload image and then change to binary & insert to db
14
by: eliss.carmine | last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first time using C# at all so I don't know if this is the "right" way to do it. I've already found out several times the way I was...
2
by: miladhatam | last post by:
i've made a dynamic website that upload an image file in image directory with fileuploader control and it's name was renamed and get ready to show with image control but i have a problem i want...
8
by: miladhatam | last post by:
can i change the size of a file dynamically ? for example have 100 Kb and i want to decrease it to 20 Kb thanks
2
by: Tark Siala | last post by:
hi i'm wprking with C# 2005 + SP1, and i want load image from image file, and then resize it (like from 800X600 Pixel to 640X480 Pixel), and then save it in another image file, i want do that for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.