Ejemplo n.º 1
0
        /// <summary>
        /// 輝度・彩度はそのままで、hueで指定された色相の色を得る。
        /// </summary>
        /// <param name="color">色</param>
        /// <param name="hue">変更先の色相(0≦hue≦360)</param>
        /// <returns>変化させた色</returns>
        public static Color MonoricColor(Color color, float hue)
        {
            ColorHSV hsv    = ColorConverter.ConvertRGBtoHSV(color);
            ColorHSV newHsv = ColorHSV.FromHSV(hue, hsv.Saturation, hsv.Value);

            return(ColorConverter.ConvertHSVtoRGB(newHsv, color.A));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// RGBからHSVへ変換を行う
        /// </summary>
        /// <param name="rgb">RGBカラー</param>
        /// <returns>HSVカラー</returns>
        public static ColorHSV ConvertRGBtoHSV(Color rgb)
        {
            int min = Math.Min(rgb.G, Math.Min(rgb.B, rgb.R));
            int max = Math.Max(rgb.G, Math.Max(rgb.B, rgb.R));

            float hue = GetHue(rgb, min, max);

            float saturation = (max != 0) ? (float)(max - min) / (float)(max) : 0f;
            float value      = (float)(max) / 255.0f;

            return(ColorHSV.FromHSV(hue, saturation, value));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// HSVの色調整を行ってピクセルデータを返す。
        /// </summary>
        /// <param name="c">カラー</param>
        /// <param name="hue">色差加算値(-360≦hue≦360)</param>
        /// <param name="saturation">彩度加割合(-255≦saturation≦255)</param>
        /// <param name="value">明度加算割合(-255≦value≦255)</param>
        /// <returns>カラー</returns>
        public static Color ProcessHSVFilter(Color c, int hue, int saturation, int value)
        {
            if (((hue == 0) && (saturation == 0) && (value == 0)))
            {
                return(c); // 色変換しない。
            }

            var   srcHSV = ColorConverter.ConvertRGBtoHSV(c);
            float h      = ColorUtility.GetHueWithLimitedRange((srcHSV.Hue + hue) % 360.0f);

            float s = ColorUtility.ModifyValueByPercent(srcHSV.Saturation, 0f, 1.0f, saturation / 255.0f);
            float v = Math.Min(ColorUtility.ModifyValueByPercent(srcHSV.Value, 0f, srcHSV.Value * 2, value / 255.0f), 1.0f);

            return(ColorConverter.ConvertHSVtoRGB(ColorHSV.FromHSV(h, s, v), c.A));
        }