/// <summary> /// Rotates the hue of an image /// </summary> /// <param name="image">Image to change</param> /// <param name="hue">Degree of hue displacement (0..360)</param> /// <remarks>Values out of range will be automatically corrected</remarks> public static void RotateHue(Image image, int hue) { using (var newImage = new Bitmap(image)) { using (var g = Graphics.FromImage(image)) { var imageAttr = new ImageAttributes(); var qm = new QColorMatrix(); qm.RotateHue(hue % 360); imageAttr.SetColorMatrix(qm.ToColorMatrix()); var destRect = new Rectangle(new Point(), image.Size); g.Clear(Color.Transparent); g.DrawImage(newImage, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr); } } }
/// <summary> /// Changes the opacity of an image. /// </summary> /// <param name="image">Image to change</param> /// <param name="opacity">Opacity change to apply (0..255)</param> /// <remarks>Values out of range will be automatically corrected</remarks> public static void ChangeOpacity(Image image, int opacity) { using (var newImage = new Bitmap(image)) { using (var g = Graphics.FromImage(image)) { var imageAttr = new ImageAttributes(); var qm = new QColorMatrix(); qm.ScaleOpacity(opacity.Clamp(0, 255) / 255.0f); imageAttr.SetColorMatrix(qm.ToColorMatrix()); var destRect = new Rectangle(new Point(), image.Size); g.Clear(Color.Transparent); g.DrawImage(newImage, destRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imageAttr); } } }