原文:WPF Color、String、Brush转换

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/BYH371256/article/details/79957419

//int 转 System.Windows.Media.Color
private System.Windows.Media.Color ToColor(int rgba)
{
return new System.Windows.Media.Color()
{
    A = Convert.ToByte((rgba >> 24) & 255),
    R = Convert.ToByte((rgba >> 16) & 255),
    G = Convert.ToByte((rgba >> 8) & 255),
    B = Convert.ToByte((rgba >> 0) & 255)
};
} //作用域:using System.Windows.Media; //由整形(int)转成Color的Argb值  A:透明值,R:红色值, G:绿色值, B:蓝色值
public static Color RgbToColor(int color)
{
    return Color.FromArgb((byte)0xff, (byte)((color & 0xff0000) >> 16), (byte)((color & 0x00ff00) >> 8), (byte)(color & 0x0000ff));
} //整形ARGB值转为Color值 Color cFrontColor = Color.FromArgb((byte)FrontColorA, (byte)style.nFrontColor_R, (byte)style.nFrontColor_G, (byte)style.nFrontColor_B); //Color 值转为整形(int)
public int ToArgb(Color color)
{
    int argb = color.A << 24;
    argb += color.R << 16;
    argb += color.G << 8;
    argb += color.B;
    return argb;
} //Color 值转R、G、B值
int fcolorR = (byte)((myRollText.FrontColor & 0xff0000) >> 16);
int fcolorG = (byte)((myRollText.FrontColor & 0x00ff00) >> 8);
int fcolorB = (byte)(myRollText.FrontColor & 0x0000ff); //整形(int)值转 SolidColorBrush类型
Color cForeBrush = RgbToColor(myRollText.FrontColor);
rollvm.RollShowVM.ForeBrush = new SolidColorBrush(cForeBrush); //Brush 转 Color            System.Windows.Media.Brush 转S ystem.Windows.Media.Color
//先将Brush转成string,再转成Color
Brush brush = ((Border)e.Source).Background;
Color c = (Color)ColorConverter.ConvertFromString(brush.ToString()); //将Brush转成SolidColorBrush,再取Color
Color color= ((SolidColorBrush)CadColor.Background).Color; //Color 转 Brush
Brush brush = new SolidColorBrush(color); //Brush 转 SolidColorBrush
SolidColorBrush ForeBrush = (SolidColorBrush)ci.ExSelectedBrush; //String 转换成 Color
Color color = (Color)ColorConverter.ConvertFromString(string); //String 转换成 Brush
BrushConverter brushConverter = new BrushConverter();
Brush brush = (Brush)brushConverter.ConvertFromString(string); //System.Windows.Media.Color 转 System.Windows.Media.Brush Color fcolor = (Color)ColorConverter.ConvertFromString(wndset.FonzColor.ToString());
var ForeColor = System.Drawing.Color.FromArgb(fcolor.A, fcolor.R, fcolor.G, fcolor.B); //System.Windows.Media.Brush 赋初值    
Brush forColor = new SolidColorBrush(System.Windows.Media.Color.FromArgb((byte)255, (byte)0,(byte)255,(byte)0));

WPF Color、String、Brush转换的更多相关文章

  1. C# Brush Color String 互相转换

    using System.Windows.Media; //String转换成Color Color color = (Color)ColorConverter.ConvertFromString(s ...

  2. c#-WPF string,color,brush之间的转换

    原文:c#-WPF string,color,brush之间的转换 String转换成Color string-"ffffff" Color color = (Color)Colo ...

  3. WPF string,color,brush之间的转换

    String转换成Color string-"ffffff" Color color = (Color)ColorConverter.ConvertFromString(strin ...

  4. wpf中将string格式的颜色转换成color类型

    wpf中Brushes有很多对应的颜色,先盗张图,每个颜色对于的名称和ARGB值有了,问题是有时候我们取到的颜色是ARGB值,而且是string类型的,该怎么转换成color呢,只有转换成color之 ...

  5. 【转】c#、wpf 字符串,color,brush之间的转换

    转自:http://www.cnblogs.com/wj-love/archive/2012/09/14/2685281.html 1,将#3C3C3C 赋给background this.selec ...

  6. WinForm和WPF颜色对象的转换

    原文:WinForm和WPF颜色对象的转换 版权声明:本文为博主原创文章,未经博主允许不得转载. https://blog.csdn.net/huangli321456/article/details ...

  7. 16进制 ,Color,Colour转换

    import java.awt.Color; import jxl.format.Colour; public class ColorUtil { public static Colour getNe ...

  8. C# Byte[] 转String 无损转换

    C# Byte[] 转String 无损转换 转载请注明出处 http://www.cnblogs.com/Huerye/ /// <summary> /// string 转成byte[ ...

  9. C# 之 将string数组转换到int数组并获取最大最小值

    1.string 数组转换到 int 数组 " }; int[] output = Array.ConvertAll<string, int>(input, delegate(s ...

随机推荐

  1. working-with-php-and-beanstalkd

    原文出处:http://www.lornajane.net/posts/2014/working-with-php-and-beanstalkd Working with PHP and Beanst ...

  2. C++作用域 (二)

    http://www.cnblogs.com/wolf-lifeng/p/3156936.html 2.3全局作用域 2.3.1概述 全局作用域是最大的名字空间作用域,不同于用户自定义的名字空间作用域 ...

  3. mavenWeb工程建立步骤

    1.File >> New >>other...,在New窗口中打开Maven,选中Maven Project,Next. 2.在New Maven Project弹出窗口中去 ...

  4. 指定Android adb的启动端口

    串口执行: setprop service.adb.tcp.port stop adbd start adbd 一般机器默认是5555为adb端口,但是今天遇到的一台机器以5037为默认端口,开发机器 ...

  5. 设计模式 - 抽象工厂模式(abstract factory pattern) 具体解释

    抽象工厂模式(abstract factory pattern) 详细解释 本文地址: http://blog.csdn.net/caroline_wendy/article/details/2709 ...

  6. iOS文本文件的编码检测

    windows上很多文本未必是用UTF8,所以在iOS上读取的时候,如何得到文件的编码是个问题.网上有很多读取中文的例子,但是那些不够通用.比如说要读取日文,韩文,阿拉伯文等等的时候,就不行了(虽然一 ...

  7. iOS 中系统与 SDK 版本检测

    一.编译时检测 1. 判断 SDK 是否是某个版本或更高版本 ifdef __IPHONE_11_0 2.判断当前需要支持的最低版本 __IPHONE_OS_VERSION_MIN_REQUIRED ...

  8. 在express中HMR(合并express和webpack-dev-server)

    在学习react的时候,经常用create-react-app来创建web应用,然而写到后面总有连自己服务器和数据库的需求,create-react-app创建的是一个webpack-dev-serv ...

  9. A - Chess Placing CodeForces - 985A

    You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted ...

  10. Ubuntu下apt方式安装与更新Git

    本人使用的系统 Ubuntu 18.04.1 ,使用apt安装Git: sudo apt insatll git 安装后发现不是最新的版本,更新方法: sudo add-apt-repository ...