Exemple #1
0
        public static ImageSource SwapColors(ImageSource imageSource, ColorCallback colorCallback)
        {
            if (colorCallback == null)
            {
                throw new ArgumentNullException("colorCallback");
            }
            ImageSource imageSource1 = imageSource;

            if (imageSource != null)
            {
                DrawingImage drawingImage;
                if ((drawingImage = imageSource as DrawingImage) != null)
                {
                    ColorSwapper.SwapColorsWithoutCloning(((DrawingImage)(imageSource1 = (ImageSource)drawingImage.Clone())).Drawing, colorCallback);
                    imageSource1.Freeze();
                }
                else
                {
                    BitmapSource bitmapSource;
                    if ((bitmapSource = imageSource as BitmapSource) != null)
                    {
                        imageSource1 = (ImageSource)ColorSwapper.SwapColors(bitmapSource, colorCallback);
                    }
                    else
                    {
                        throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ExceptionStringTable.UnexpectedImageSourceType, new object[1]
                        {
                            (object)imageSource.GetType().Name
                        }));
                    }
                }
            }
            return(imageSource1);
        }
Exemple #2
0
        private static ImageSource SwapColorsWithoutCloningIfPossible(ImageSource imageSource, ColorCallback colorCallback)
        {
            ImageSource imageSource1 = imageSource;

            if (imageSource != null)
            {
                DrawingImage drawingImage;
                if ((drawingImage = imageSource as DrawingImage) != null)
                {
                    ColorSwapper.SwapColorsWithoutCloning(drawingImage.Drawing, colorCallback);
                }
                else
                {
                    BitmapSource bitmapSource;
                    if ((bitmapSource = imageSource as BitmapSource) != null)
                    {
                        imageSource1 = (ImageSource)ColorSwapper.SwapColors(bitmapSource, colorCallback);
                    }
                    else
                    {
                        throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ExceptionStringTable.UnexpectedImageSourceType, new object[1]
                        {
                            (object)imageSource.GetType().Name
                        }));
                    }
                }
            }
            return(imageSource1);
        }