ARCed.Helpers.Cache.ChangeHueOpacity C# (CSharp) 메소드

ChangeHueOpacity() 공개 정적인 메소드

Rotates the hue and alters the opacity of an image. Using this method is more efficient than performing the actions separately.
Values out of range will be automatically corrected
public static ChangeHueOpacity ( Image image, int hue, int opacity ) : void
image Image Image to change
hue int Degree of hue displacement (0..360)
opacity int Opacity change to apply (0..255)
리턴 void
        public static void ChangeHueOpacity(Image image, int hue, int opacity)
        {
            using (var newImage = new Bitmap(image))
            {
                using (var g = Graphics.FromImage(image))
                {
                    var imageAttr = new ImageAttributes();
                    var qm = new QColorMatrix();
                    qm.RotateHue(hue % 360);
                    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);
                }
            }
        }