From aaf082fabad350d24b1fd94da3ddff5e31b905f7 Mon Sep 17 00:00:00 2001 From: Dinis Vieira Date: Wed, 25 Oct 2023 22:20:01 +0100 Subject: [PATCH] PM-3349 Fixed white tint color not appearing on images added as MAU IImage SVG PM-3349 PM-3350 Fix for Avatar text not adjusting to white/black color correctly --- src/App/App.csproj | 4 ++-- src/Core/Utilities/CoreHelpers.cs | 11 +++++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/App/App.csproj b/src/App/App.csproj index a33e55f32..eb7b3724d 100644 --- a/src/App/App.csproj +++ b/src/App/App.csproj @@ -219,10 +219,10 @@ 24,24 - + 24,24 - + 24,24 diff --git a/src/Core/Utilities/CoreHelpers.cs b/src/Core/Utilities/CoreHelpers.cs index cd8f37f8d..95ba708c2 100644 --- a/src/Core/Utilities/CoreHelpers.cs +++ b/src/Core/Utilities/CoreHelpers.cs @@ -267,13 +267,16 @@ namespace Bit.Core.Utilities public static string TextColorFromBgColor(string hexColor, int threshold = 166) { - if (new ColorConverter().ConvertFromString(hexColor) is Color bgColor) + var isValidColor = Color.TryParse(hexColor, out var bgColor); + if (isValidColor) { - var luminance = bgColor.Red * 0.299 + bgColor.Green * 0.587 + bgColor.Blue * 0.114; + var luminance = (bgColor.Red * 255 * 0.299) + (bgColor.Green * 255 * 0.587) + (bgColor.Blue * 255 * 0.114); return luminance > threshold ? "#ff000000" : "#ffffffff"; } - - return "#ff000000"; + else + { + return "#ff000000"; + } } public static string StringToColor(string str, string fallback)