How can I rotate the hue of an image using GDI+'s ImageAttributes
(and presumably ColorMatrix
)?
Note that I want to rotate the hue, not tint the image.
EDIT: By rotating the hue, I mean that each color in the image should be shifted to a different color, as opposed to making the entire image a shade of one color.
For example,
Original:http://www.codeguru.com/img/legacy/gdi/Tinter03.jpg
Rotated: http://www.codeguru.com/img/legacy/gdi/Tinter15.jpg or http://www.codeguru.com/img/legacy/gdi/Tinter17.jpg
I threw this together for this question (ZIP file with c# project linked at the bottom of the post). It does not use ImageAttributes
or ColorMatrix
, but it rotates the hue as you've described:
//rotate hue for a pixel
private Color CalculateHueChange(Color oldColor, float hue)
{
HLSRGB color = new HLSRGB(
Convert.ToByte(oldColor.R),
Convert.ToByte(oldColor.G),
Convert.ToByte(oldColor.B));
float startHue = color.Hue;
color.Hue = startHue + hue;
return color.Color;
}
I ended up porting QColorMatrix to C# and using its RotateHue
method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With