Convert a Color to unsigned int - CSharp System.Drawing

CSharp examples for System.Drawing:Color Convert

Description

Convert a Color to unsigned int

Demo Code


using System.Windows.Media;
using System.Globalization;
using System;/*w w  w  .jav a  2  s  .co m*/

public class Main{
        /// <summary>
        /// Convert a <see cref="Color"/> to unsigned int
        /// </summary>
        /// <param name="c">
        /// </param>
        /// <returns>
        /// The color to uint.
        /// </returns>
        public static uint ColorToUint(Color c)
        {
            uint u = (UInt32)c.A << 24;
            u += (UInt32)c.R << 16;
            u += (UInt32)c.G << 8;
            u += c.B;
            return u;

            // (UInt32)((UInt32)c.A << 24 + (UInt32)c.R << 16 + (UInt32)c.G << 8 + (UInt32)c.B);
        }
}

Related Tutorials