473,666 Members | 2,096 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 21502

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.HS VtoRGB 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.HS VtoRGB 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 fractionalSecto r;
int sectorNumber;
double sectorPos;

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

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

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

// 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.mi crosoft.com ("Jeffrey Tan[MSFT]") wrote in
news:0d******** *****@cpmsftngx a07.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
1247
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: Clipboard.SetDataObject( ChartBitmap ); after which I paste that bitmap into MS Word. Some of the colors change or don't show up when the bitmap is pasted into Word. This
2
3695
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 Bitmap(Width,Height,PixelFormat.Format24bppRgb); i have a bitmapdata class and then lock the bits like this. bitmapData = bitmap.LockBits(bounds, ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
2
8526
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 like "gcnew is undeclared error",how to deeclare 'gcnew" and when i am using in runtime to change the size of images in imagelist in listview control in .net(forms application) by chnging one trckbar(like tb1->Value),
7
8236
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
2354
by: joe | last post by:
how to resize an upload image and then change to binary & insert to db
14
11890
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 doing something was really inefficient and could reduce 10 lines of code with 2, etc. For reading, I am using a TcpClient and I call NetworkStream ns = client.GetStream(); to get a stream stream.Read(buffer, 0, buffer.Length);
2
1674
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 to change the size of image and decrease it's size and i have another question how can i show an image file in an image control with maintaining the aspect ratio of that i don't wanna the image control stretch the image
8
2338
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
7663
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 resize many images to publish it on the internet, the picture box can load image and resize it on the screen, but can't save it with new dimension. can you help me? ----------- Tarek M. Siala
0
8871
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8783
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8552
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8640
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7387
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6198
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4198
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2773
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1776
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.