diff --git a/ShareX.HelpersLib/Helpers/ImageHelpers.cs b/ShareX.HelpersLib/Helpers/ImageHelpers.cs
index a3b1cecfc..ee43faea6 100644
--- a/ShareX.HelpersLib/Helpers/ImageHelpers.cs
+++ b/ShareX.HelpersLib/Helpers/ImageHelpers.cs
@@ -2325,6 +2325,30 @@ public static void SelectiveColor(Bitmap bmp, Color lightColor, Color darkColor,
}
}
+ public static void ReplaceColor(Bitmap bmp, Color sourceColor, Color targetColor, bool autoSourceColor = false)
+ {
+ ColorBgra sourceBgra = new ColorBgra(sourceColor);
+ ColorBgra targetBgra = new ColorBgra(targetColor);
+
+ using (UnsafeBitmap unsafeBitmap = new UnsafeBitmap(bmp, true))
+ {
+ if (autoSourceColor)
+ {
+ sourceBgra = unsafeBitmap.GetPixel(0);
+ }
+
+ for (int i = 0; i < unsafeBitmap.PixelCount; i++)
+ {
+ ColorBgra color = unsafeBitmap.GetPixel(i);
+
+ if (color == sourceBgra)
+ {
+ unsafeBitmap.SetPixel(i, targetBgra);
+ }
+ }
+ }
+ }
+
public static Size GetImageFileDimensions(string filePath)
{
using (Bitmap bmp = LoadImage(filePath))
diff --git a/ShareX.ImageEffectsLib/Adjustments/ReplaceColor.cs b/ShareX.ImageEffectsLib/Adjustments/ReplaceColor.cs
new file mode 100644
index 000000000..9ed17b51d
--- /dev/null
+++ b/ShareX.ImageEffectsLib/Adjustments/ReplaceColor.cs
@@ -0,0 +1,56 @@
+#region License Information (GPL v3)
+
+/*
+ ShareX - A program that allows you to take screenshots and share any file type
+ Copyright (c) 2007-2021 ShareX Team
+
+ This program is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License
+ as published by the Free Software Foundation; either version 2
+ of the License, or (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+ Optionally you can also view the license at .
+*/
+
+#endregion License Information (GPL v3)
+
+using ShareX.HelpersLib;
+using System.ComponentModel;
+using System.Drawing;
+using System.Drawing.Design;
+
+namespace ShareX.ImageEffectsLib
+{
+ [Description("Replace color")]
+ internal class ReplaceColor : ImageEffect
+ {
+ [DefaultValue(typeof(Color), "White"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
+ public Color SourceColor { get; set; }
+
+ [DefaultValue(false)]
+ public bool AutoSourceColor { get; set; }
+
+ [DefaultValue(typeof(Color), "Transparent"), Editor(typeof(MyColorEditor), typeof(UITypeEditor)), TypeConverter(typeof(MyColorConverter))]
+ public Color TargetColor { get; set; }
+
+ public ReplaceColor()
+ {
+ this.ApplyDefaultPropertyValues();
+ }
+
+ public override Bitmap Apply(Bitmap bmp)
+ {
+ ImageHelpers.ReplaceColor(bmp, SourceColor, TargetColor, AutoSourceColor);
+ return bmp;
+ }
+ }
+}
\ No newline at end of file
diff --git a/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs b/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs
index e2a717b46..9d5290a32 100644
--- a/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs
+++ b/ShareX.ImageEffectsLib/Forms/ImageEffectsForm.cs
@@ -180,6 +180,7 @@ private void AddAllEffectsToContextMenu()
typeof(Hue),
typeof(Inverse),
typeof(Polaroid),
+ typeof(ReplaceColor),
typeof(Saturation),
typeof(SelectiveColor),
typeof(Sepia));
diff --git a/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj b/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj
index d0fc37f68..09ca21f62 100644
--- a/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj
+++ b/ShareX.ImageEffectsLib/ShareX.ImageEffectsLib.csproj
@@ -105,6 +105,7 @@
+