WinForm和WPF颜色对象的转换

原文: WinForm和WPF颜色对象的转换


///
        /// 将wpf的颜色对象转换为整型的Winform颜色值
        ///

        ///
        ///
        public static String ConvertWpfBrushToWFColorArgb(media.SolidColorBrush brush)
        {
            return (brush.Color.A << 24 | brush.Color.R << 16 | brush.Color.G << 8 | brush.Color.B).ToString();
        }
        ///
        /// 将来自winform的argb整型颜色值转换为wpf颜色对象
        ///

        ///
        ///
        public static System.Windows.Media.SolidColorBrush ConvertWFColorToWfpBrush(int wfargb)
        {
            return new System.Windows.Media.SolidColorBrush()
            {
                Color = new media.Color()
                {
                    A = (byte)((wfargb >> 24) & 0xFF),
                    R = (byte)((wfargb >> 16) & 0xFF),
                    G = (byte)((wfargb >> 8) & 0xFF),
                    B = (byte)(wfargb & 0xFF)
                }
            };
        }

你可能感兴趣的:(WinForm和WPF颜色对象的转换)