From 78024eeaabd0f1cb0dd18da1d08980a5db66c694 Mon Sep 17 00:00:00 2001 From: James South Date: Tue, 23 Sep 2014 17:16:53 +0100 Subject: [PATCH] Allow transparent replacement. Former-commit-id: e167a511e5c58f3a3a3b80c7026d663711b570cb --- src/ImageProcessor/Processors/ReplaceColor.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ImageProcessor/Processors/ReplaceColor.cs b/src/ImageProcessor/Processors/ReplaceColor.cs index a8a7f810e2..9e3df1eeb9 100644 --- a/src/ImageProcessor/Processors/ReplaceColor.cs +++ b/src/ImageProcessor/Processors/ReplaceColor.cs @@ -75,6 +75,7 @@ namespace ImageProcessor.Processors byte replacementR = original.R; byte replacementG = replacement.G; byte replacementB = replacement.B; + byte replacementA = replacement.A; int fuzziness = parameters.Item3; @@ -93,6 +94,7 @@ namespace ImageProcessor.Processors byte currentR = currentColor.R; byte currentG = currentColor.B; byte currentB = currentColor.B; + byte currentA = currentColor.A; // Test whether it is in the expected range. if (currentR <= originalR + fuzziness && currentR >= originalR - fuzziness) @@ -106,7 +108,11 @@ namespace ImageProcessor.Processors byte r = (originalR - currentR + replacementR).ToByte(); byte g = (originalG - currentG + replacementG).ToByte(); byte b = (originalB - currentB + replacementB).ToByte(); - fastBitmap.SetPixel(x, y, Color.FromArgb(currentColor.A, r, g, b)); + + // Allow replacement with transparent color. + byte a = currentA != replacementA ? replacementA : currentA; + + fastBitmap.SetPixel(x, y, Color.FromArgb(a, r, g, b)); } } }