473,322 Members | 1,755 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,322 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 21428

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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.