/// <summary> /// Swap the colors in an image based on a color mapping provided by the ColorCallback</summary> /// <param name="imageSource">Original image</param> /// <param name="colorCallback">Callback to provide the color mapping</param> /// <returns>Color-swapped image</returns> public static ImageSource SwapColors(ImageSource imageSource, ColorCallback colorCallback) { if (colorCallback == null) { throw new ArgumentNullException("colorCallback"); } ImageSource source = imageSource; if (imageSource == null) { return(source); } DrawingImage image = imageSource as DrawingImage; if (image != null) { source = image = image.Clone(); SwapColorsWithoutCloning(image.Drawing, colorCallback); source.Freeze(); return(source); } BitmapSource bitmapSource = imageSource as BitmapSource; if (bitmapSource == null) { throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "UnexpectedImageSourceType", new object[] { imageSource.GetType().Name })); } return(SwapColors(bitmapSource, colorCallback)); }