Skip to content

Commit a8b991d

Browse files
authored
Fix: Fixed color conversion helpers (#12036)
1 parent 323545a commit a8b991d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/Files.App/Helpers/ColorHelpers.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,26 @@ public static string RandomColor()
7676
return color.ToHex();
7777
}
7878

79+
private static string ToHex(this System.Drawing.Color color)
80+
{
81+
return $"#{color.A:X2}{color.R:X2}{color.G:X2}{color.B:X2}";
82+
}
83+
7984
public static Windows.UI.Color ToWindowsColor(this System.Drawing.Color color)
8085
{
81-
return Windows.UI.Color.FromArgb(color.A, color.R, color.G, color.B);
86+
string hex = color.ToHex();
87+
return FromHex(hex);
8288
}
8389

8490
public static System.Drawing.Color FromWindowsColor(this Windows.UI.Color color)
8591
{
86-
return System.Drawing.Color.FromArgb(color.ToInt());
92+
string hex = color.ToHex();
93+
94+
return System.Drawing.Color.FromArgb(
95+
Convert.ToByte(hex.Substring(1, 2), 16),
96+
Convert.ToByte(hex.Substring(3, 2), 16),
97+
Convert.ToByte(hex.Substring(5, 2), 16),
98+
Convert.ToByte(hex.Substring(7, 2), 16));
8799
}
88100
}
89101
}

0 commit comments

Comments
 (0)