Convert an unsigned int (32bit) to Color - CSharp System.Drawing

CSharp examples for System.Drawing:Color Convert

Description

Convert an unsigned int (32bit) to Color

Demo Code


using System.Windows.Media;
using System.Globalization;
using System;//www. ja  v  a 2 s. c om

public class Main{
        /// <summary>
        /// Convert an unsigned int (32bit) to <see cref="Color"/>
        /// </summary>
        /// <param name="color">
        /// </param>
        /// <returns>
        /// </returns>
        public static Color UIntToColor(uint color)
        {
            var a = (byte)(color >> 24);
            var r = (byte)(color >> 16);
            var g = (byte)(color >> 8);
            var b = (byte)(color >> 0);
            return Color.FromArgb(a, r, g, b);
        }
}

Related Tutorials