代码
private
Color ReturnColorFromString(
string
color)
{
string alpha = color.Substring( 0 , 2 );
string red = color.Substring( 2 , 2 );
string green = color.Substring( 4 , 2 );
string blue = color.Substring( 6 , 2 );
byte alphaByte = Convert.ToByte(alpha, 16 );
byte redByte = Convert.ToByte(red, 16 );
byte greenByte = Convert.ToByte(green, 16 );
byte blueByte = Convert.ToByte(blue, 16 );
return Color.FromArgb(alphaByte, redByte, greenByte, blueByte);
}
{
string alpha = color.Substring( 0 , 2 );
string red = color.Substring( 2 , 2 );
string green = color.Substring( 4 , 2 );
string blue = color.Substring( 6 , 2 );
byte alphaByte = Convert.ToByte(alpha, 16 );
byte redByte = Convert.ToByte(red, 16 );
byte greenByte = Convert.ToByte(green, 16 );
byte blueByte = Convert.ToByte(blue, 16 );
return Color.FromArgb(alphaByte, redByte, greenByte, blueByte);
}
颜色到数:
public
static
int
ToArgb(
this
Color color) {
int argb = color.A << 24 ;
argb += color.R << 16 ;
argb += color.G << 8 ;
argb += color.B;
return argb;
}
int argb = color.A << 24 ;
argb += color.R << 16 ;
argb += color.G << 8 ;
argb += color.B;
return argb;
}