예제 #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);
        }
예제 #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);
        }
예제 #3
0
        private static void SwapColorsWithoutCloning(Drawing drawing, ColorCallback colorCallback)
        {
            if (drawing == null)
            {
                return;
            }
            DrawingGroup drawingGroup;

            if ((drawingGroup = drawing as DrawingGroup) != null)
            {
                for (int index = 0; index < drawingGroup.Children.Count; ++index)
                {
                    ColorSwapper.SwapColorsWithoutCloning(drawingGroup.Children[index], colorCallback);
                }
            }
            else
            {
                GeometryDrawing geometryDrawing;
                if ((geometryDrawing = drawing as GeometryDrawing) != null)
                {
                    ColorSwapper.SwapColorsWithoutCloning(geometryDrawing.Brush, colorCallback);
                    if (geometryDrawing.Pen == null)
                    {
                        return;
                    }
                    ColorSwapper.SwapColorsWithoutCloning(geometryDrawing.Pen.Brush, colorCallback);
                }
                else
                {
                    GlyphRunDrawing glyphRunDrawing;
                    if ((glyphRunDrawing = drawing as GlyphRunDrawing) != null)
                    {
                        ColorSwapper.SwapColorsWithoutCloning(glyphRunDrawing.ForegroundBrush, colorCallback);
                    }
                    else
                    {
                        ImageDrawing imageDrawing;
                        if ((imageDrawing = drawing as ImageDrawing) != null)
                        {
                            imageDrawing.ImageSource = ColorSwapper.SwapColorsWithoutCloningIfPossible(imageDrawing.ImageSource, colorCallback);
                        }
                        else if (!(drawing is VideoDrawing))
                        {
                            throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ExceptionStringTable.UnexpectedDrawingType, new object[1]
                            {
                                (object)drawing.GetType().Name
                            }));
                        }
                    }
                }
            }
        }
예제 #4
0
        public static Drawing SwapColors(Drawing drawing, ColorCallback colorCallback)
        {
            if (colorCallback == null)
            {
                throw new ArgumentNullException("colorCallback");
            }
            Drawing drawing1 = drawing;

            if (drawing != null)
            {
                drawing1 = drawing.Clone();
                ColorSwapper.SwapColorsWithoutCloning(drawing1, colorCallback);
                drawing1.Freeze();
            }
            return(drawing1);
        }
예제 #5
0
        public static Brush SwapColors(Brush brush, ColorCallback colorCallback)
        {
            if (colorCallback == null)
            {
                throw new ArgumentNullException("colorCallback");
            }
            Brush brush1 = brush;

            if (brush != null)
            {
                brush1 = brush.Clone();
                ColorSwapper.SwapColorsWithoutCloning(brush1, colorCallback);
                brush1.Freeze();
            }
            return(brush1);
        }
예제 #6
0
        private static void SwapColorsWithoutCloning(Brush brush, ColorCallback colorCallback)
        {
            if (brush == null)
            {
                return;
            }
            SolidColorBrush solidColorBrush;

            if ((solidColorBrush = brush as SolidColorBrush) != null)
            {
                solidColorBrush.Color = colorCallback(solidColorBrush.Color);
            }
            else
            {
                GradientBrush gradientBrush;
                if ((gradientBrush = brush as GradientBrush) != null)
                {
                    foreach (GradientStop gradientStop in gradientBrush.GradientStops)
                    {
                        gradientStop.Color = colorCallback(gradientStop.Color);
                    }
                }
                else
                {
                    DrawingBrush drawingBrush;
                    if ((drawingBrush = brush as DrawingBrush) != null)
                    {
                        ColorSwapper.SwapColorsWithoutCloning(drawingBrush.Drawing, colorCallback);
                    }
                    else
                    {
                        ImageBrush imageBrush;
                        if ((imageBrush = brush as ImageBrush) != null)
                        {
                            imageBrush.ImageSource = ColorSwapper.SwapColorsWithoutCloningIfPossible(imageBrush.ImageSource, colorCallback);
                        }
                        else if (!(brush is VisualBrush))
                        {
                            throw new ArgumentException(string.Format((IFormatProvider)CultureInfo.CurrentCulture, ExceptionStringTable.UnexpectedBrushType, new object[1]
                            {
                                (object)brush.GetType().Name
                            }));
                        }
                    }
                }
            }
        }