Ejemplo n.º 1
0
        /// <summary>
        /// Get Hex long RGB channel, f.e. 0xFF112233 -> 0x112233
        /// </summary>
        /// <param name="x">
        ///  data object Color, Hex, HexL, string
        /// </param>
        /// <returns></returns>
        public static long RgbLChannel(this object x)
        {
            if (x == null)
            {
                return(0x000000);
            }

            try
            {
                var c = (Color)x;
                return(((c.R << 16) | (c.G << 8) | c.B) & 0xffffffL);
            }
            catch (Exception)
            {
                try
                {
                    var i = (int)x;
                    return(i & 0xffffffL);
                }
                catch (Exception)
                {
                    try
                    {
                        var u = (uint)x;
                        return(u & 0xffffffL);
                    }
                    catch (Exception)
                    {
                        try
                        {
                            var u = (long)x;
                            return(u & 0xffffffL);
                        }
                        catch (Exception)
                        {
                            try
                            {
                                var str = (string)x;
                                var c   = ColorFrom.String(str);
                                return((long)(((c.R << 16) | (c.G << 8) | c.B) & 0xffffffL));
                            }
                            catch (Exception e)
                            {
                                throw new InvalidOperationException("Color convert Error", e);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static Color Object(object color)
        {
            var c = 0x00000000.ToColor();

            if (color == null)
            {
                return(c);
            }

            try
            {
                c = (Color)color;
            }
            catch (Exception)
            {
                try
                {
                    c = ((int)color).ToColor();
                }
                catch (Exception)
                {
                    try
                    {
                        c = ((uint)color).ToColor();
                    }
                    catch (Exception)
                    {
                        try
                        {
                            c = ((long)color).ToColor();
                        }
                        catch (Exception)
                        {
                            try
                            {
                                c = ColorFrom.String((string)color);
                            }
                            catch (Exception e)
                            {
                                throw new InvalidOperationException("Color convert Error", e);
                            }
                        }
                    }
                }
            }

            return(c);
        }