Skip to content

Commit cb27b6d

Browse files
Context Menu Tags Colors
1 parent de9b29d commit cb27b6d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Files.App/Helpers/ColorHelpers.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ internal static class ColorHelpers
1212
public static Color FromHex(string colorHex)
1313
{
1414
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);
1815

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);
2024
}
2125

2226
/// <summary>

0 commit comments

Comments
 (0)