File tree Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Expand file tree Collapse file tree 1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -12,11 +12,15 @@ internal static class ColorHelpers
12
12
public static Color FromHex ( string colorHex )
13
13
{
14
14
colorHex = colorHex . Replace ( "#" , string . Empty ) ;
15
- var r = ( byte ) Convert . ToUInt32 ( colorHex . Substring ( 0 , 2 ) , 16 ) ;
16
- var g = ( byte ) Convert . ToUInt32 ( colorHex . Substring ( 2 , 2 ) , 16 ) ;
17
- var b = ( byte ) Convert . ToUInt32 ( colorHex . Substring ( 4 , 2 ) , 16 ) ;
18
15
19
- return Color . FromArgb ( 255 , r , g , b ) ;
16
+ var alphaOffset = colorHex . Length == 8 ? 2 : 0 ;
17
+
18
+ var a = alphaOffset == 2 ? ( byte ) Convert . ToUInt32 ( colorHex . Substring ( 0 , 2 ) , 16 ) : ( byte ) 255 ;
19
+ var r = ( byte ) Convert . ToUInt32 ( colorHex . Substring ( alphaOffset , 2 ) , 16 ) ;
20
+ var g = ( byte ) Convert . ToUInt32 ( colorHex . Substring ( alphaOffset + 2 , 2 ) , 16 ) ;
21
+ var b = ( byte ) Convert . ToUInt32 ( colorHex . Substring ( alphaOffset + 4 , 2 ) , 16 ) ;
22
+
23
+ return Color . FromArgb ( a , r , g , b ) ;
20
24
}
21
25
22
26
/// <summary>
You can’t perform that action at this time.
0 commit comments