2021-11-22 13:31:31 +00:00
|
|
|
|
// Copyright (c) Microsoft Corporation
|
|
|
|
|
|
// The Microsoft Corporation licenses this file to you under the MIT license.
|
|
|
|
|
|
// See the LICENSE file in the project root for more information.
|
|
|
|
|
|
|
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Microsoft.PowerToys.Settings.UI.Library.Helpers
|
|
|
|
|
|
{
|
|
|
|
|
|
public static class SettingsUtilities
|
|
|
|
|
|
{
|
|
|
|
|
|
public static string ToRGBHex(string color)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (color == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "#FFFFFF";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Using InvariantCulture as these are expected to be hex codes.
|
|
|
|
|
|
bool success = int.TryParse(
|
|
|
|
|
|
color.Replace("#", string.Empty),
|
|
|
|
|
|
System.Globalization.NumberStyles.HexNumber,
|
|
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
|
|
out int argb);
|
|
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
|
{
|
|
|
|
|
|
Color clr = Color.FromArgb(argb);
|
|
|
|
|
|
return "#" + clr.R.ToString("X2", CultureInfo.InvariantCulture) +
|
|
|
|
|
|
clr.G.ToString("X2", CultureInfo.InvariantCulture) +
|
|
|
|
|
|
clr.B.ToString("X2", CultureInfo.InvariantCulture);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return "#FFFFFF";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-07-26 23:48:00 +09:00
|
|
|
|
|
|
|
|
|
|
public static string ToARGBHex(string color)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (color == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
return "#FFFFFFFF";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Using InvariantCulture as these are expected to be hex codes.
|
|
|
|
|
|
bool success = int.TryParse(
|
|
|
|
|
|
color.Replace("#", string.Empty),
|
|
|
|
|
|
System.Globalization.NumberStyles.HexNumber,
|
|
|
|
|
|
CultureInfo.InvariantCulture,
|
|
|
|
|
|
out int argb);
|
|
|
|
|
|
|
|
|
|
|
|
if (success)
|
|
|
|
|
|
{
|
|
|
|
|
|
Color clr = Color.FromArgb(argb);
|
|
|
|
|
|
return "#" + clr.A.ToString("X2", CultureInfo.InvariantCulture) +
|
|
|
|
|
|
clr.R.ToString("X2", CultureInfo.InvariantCulture) +
|
|
|
|
|
|
clr.G.ToString("X2", CultureInfo.InvariantCulture) +
|
|
|
|
|
|
clr.B.ToString("X2", CultureInfo.InvariantCulture);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return "#FFFFFFFF";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2021-11-22 13:31:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|