Converts from a Color to HSV values (byte) - CSharp System.Drawing

CSharp examples for System.Drawing:Color Convert

Description

Converts from a Color to HSV values (byte)

Demo Code


using System.Windows.Media;
using System.Globalization;
using System;/*from  www .  j av  a  2 s  .c o  m*/

public class Main{
        /// <summary>
        /// Converts from a <see cref="Color"/> to HSV values (byte)
        /// </summary>
        /// <param name="color">
        /// </param>
        /// <returns>
        /// Array of [Hue,Saturation,Value] in the range [0,255]
        /// </returns>
        public static byte[] ColorToHsvBytes(Color color)
        {
            double[] hsv1 = ColorToHsv(color);
            var hsv2 = new byte[3];
            hsv2[0] = (byte)(hsv1[0] * 255);
            hsv2[1] = (byte)(hsv1[1] * 255);
            hsv2[2] = (byte)(hsv1[2] * 255);
            return hsv2;
        }
}

Related Tutorials