// Add Blur effect.
        void OnClickBlurButton(object sender, RoutedEventArgs args)
        {
            // Toggle effect
            if (((Button)sender).BitmapEffect != null)
            {
                ((Button)sender).BitmapEffect = null;
            }
            else
            {
                // <SnippetCodeBehindBlurCodeBehindExampleInline>
                // Get a reference to the Button.
                Button myButton = (Button)sender;

                // Initialize a new BlurBitmapEffect that will be applied
                // to the Button.
                BlurBitmapEffect myBlurEffect = new BlurBitmapEffect();

                // Set the Radius property of the blur. This determines how
                // blurry the effect will be. The larger the radius, the more
                // blurring.
                myBlurEffect.Radius = 10;

                // Set the KernelType property of the blur. A KernalType of "Box"
                // creates less blur than the Gaussian kernal type.
                myBlurEffect.KernelType = KernelType.Box;

                // Apply the bitmap effect to the Button.
                myButton.BitmapEffect = myBlurEffect;
                // </SnippetCodeBehindBlurCodeBehindExampleInline>
            }
        }
        public MultipleEffectExample()
        {
            Button myButton = new Button();

            myButton.Content = "DropShadow under this Button";
            myButton.Margin  = new Thickness(50);
            myButton.Width   = 300;

            // Create the BitmapEffects to apply to the button.
            BlurBitmapEffect myBlurBitmapEffect = new BlurBitmapEffect();

            myBlurBitmapEffect.Radius = 2;

            DropShadowBitmapEffect myDropShadowBitmapEffect = new DropShadowBitmapEffect();

            myDropShadowBitmapEffect.Color       = Colors.Black;
            myDropShadowBitmapEffect.Direction   = 320;
            myDropShadowBitmapEffect.ShadowDepth = 30;
            myDropShadowBitmapEffect.Softness    = 1;
            myDropShadowBitmapEffect.Opacity     = 0.5;

            BitmapEffectGroup myBitmapEffectGroup = new BitmapEffectGroup();

            myBitmapEffectGroup.Children.Add(myBlurBitmapEffect);
            myBitmapEffectGroup.Children.Add(myDropShadowBitmapEffect);

            myButton.BitmapEffect = myBitmapEffectGroup;

            StackPanel myStackPanel = new StackPanel();

            myStackPanel.Children.Add(myButton);
            this.Content = myStackPanel;
        }
Exemple #3
0
        public MainWindow()
        {
            InitializeComponent();

            var screenwidth  = (SystemParameters.PrimaryScreenWidth);
            var screenheight = (SystemParameters.PrimaryScreenHeight);

            wallpaper_instance.Source = Screenshot.CopyScreen();
            wallpaper_instance.Width  = screenwidth;
            wallpaper_instance.Height = screenheight;
            RenderOptions.SetBitmapScalingMode(wallpaper_instance, BitmapScalingMode.LowQuality);

            canvas.Children.Add(wallpaper_instance);

            BlurBitmapEffect myBlurEffect = new BlurBitmapEffect();

            // Set the Radius property of the blur. This determines how
            // blurry the effect will be. The larger the radius, the more
            // blurring.
            myBlurEffect.Radius = 15;

            // Set the KernelType property of the blur. A KernalType of "Box"
            // creates less blur than the Gaussian kernal type.
            myBlurEffect.KernelType = KernelType.Box;

            // Apply the bitmap effect to the Button.
            wallpaper_instance.BitmapEffect = myBlurEffect;
        }
Exemple #4
0
        /// <summary>
        /// This summary has not been prepared yet. NOSUMMARY - pantal07
        /// </summary>
        public static BitmapEffect Blur(double radius)
        {
            BlurBitmapEffect effect = new BlurBitmapEffect();

            effect.Radius = radius;

            return(effect);
        }
Exemple #5
0
        //==========================================================================
        public override BitmapEffect ToBitmapEffect()
        {
            BlurBitmapEffect blur_bitmap_effect = new BlurBitmapEffect();

            blur_bitmap_effect.Radius     = StdDeviation.ToDouble();
            blur_bitmap_effect.KernelType = KernelType.Box;
            return(blur_bitmap_effect);
        }
        public void QuitarEfecto()
        {
            BlurBitmapEffect myBlurEffect = new BlurBitmapEffect();

            myBlurEffect.Radius     = 0;
            myBlurEffect.KernelType = KernelType.Box;
            main.BitmapEffect       = myBlurEffect;
        }
Exemple #7
0
        public void addEfecto()
        {
            BlurBitmapEffect myBlurEffect = new BlurBitmapEffect();

            myBlurEffect.Radius     = 2;
            myBlurEffect.KernelType = KernelType.Box;
            this.main.BitmapEffect  = myBlurEffect;
        }
Exemple #8
0
        private void Blur_OnClick(object sender, RoutedEventArgs e)
        {
            BlurBitmapEffect blurEffect = new BlurBitmapEffect();

            blurEffect.Radius = this.ShaderStrength.Value;

            blurEffect.KernelType = KernelType.Box;
            foreach (Line canvasChild in this.Canvas.Children)
            {
                canvasChild.BitmapEffect = blurEffect;
            }
        }
Exemple #9
0
        public MainWindow()
        {
            InitializeComponent();
            ball = new Energy();
            canvas.Children.Add(ball.Shape);
            BitmapImage bm = new BitmapImage();

            bm.BeginInit();
            bm.UriSource = new Uri("cat.jpg", UriKind.Relative);
            bm.EndInit();
            imageForMW.Source       = bm;
            myBlurEffect            = new BlurBitmapEffect();
            myBlurEffect.Radius     = 50;
            imageForMW.BitmapEffect = myBlurEffect;
        }
 private void BlurWindow(bool blur)
 {
     if (blur == true)
     {
         BlurBitmapEffect effect = new BlurBitmapEffect();
         effect.Radius           = 10;
         effect.KernelType       = KernelType.Gaussian;
         mainGrid.BitmapEffect   = effect;
         progressGrid.Visibility = Visibility.Visible;
     }
     else
     {
         mainGrid.BitmapEffect   = null;
         progressGrid.Visibility = Visibility.Hidden;
     }
 }
        private void OnClick_Lock(object sender, MouseButtonEventArgs e)
        {
            BlurBitmapEffect myBlurEffect = new BlurBitmapEffect();

            myBlurEffect.Radius     = 10;
            myBlurEffect.KernelType = KernelType.Box;

            foreach (UIElement uiElement in gMain.Children)
            {
                if (uiElement.BitmapEffect == null)
                {
                    //If Listview Element, apply Blur
                    if (uiElement is ListView)
                    {
                        uiElement.BitmapEffect = myBlurEffect;
                    }

                    if (uiElement is DockPanel)
                    {
                        DockPanel dpTemp = uiElement as DockPanel;

                        if (dpTemp.Name.Equals("dpCalendarHeader") || dpTemp.Name.Equals("dpTaskHeader"))
                        {
                            dpTemp.BitmapEffect = myBlurEffect;
                        }

                        if (dpTemp.Name.Equals("dpLockHeader"))
                        {
                            Image imgTemp = dpTemp.Children[0] as Image;

                            if (imgTemp.Source.ToString().ToLower().Contains("open"))
                            {
                                imgTemp.Source = new BitmapImage(new Uri(@"res\icon_LockClosed.png", UriKind.Relative));
                            }
                            else
                            {
                                imgTemp.Source = new BitmapImage(new Uri(@"res\icon_LockOpen.png", UriKind.Relative));
                            }
                        }
                    }
                }
                else
                {
                    uiElement.BitmapEffect = null;
                }
            }
        }
Exemple #12
0
        private void btnPauseCall_Click(object sender, RoutedEventArgs e)
        {
            // Если удерживаем звонок
            if (this.call != null)
            {
#warning HoldCallDisactieve
                // add call to call stack
                Softphone.HoldCall(this.call);
                //Softphone.HoldCall(this.call);
                Classes.LocalAudioPlayer.PlaySound(Properties.Resources.notification_delayed);
                // apply blur effect to infoPanel
                BlurBitmapEffect effect = new BlurBitmapEffect();
                borderCallNotification.Background = Brushes.LightGray;
                effect.Radius     = 4;
                effect.KernelType = KernelType.Gaussian;
                borderCallNotification.BitmapEffect = effect;
            }
        }
Exemple #13
0
        public MiniGame1(BitmapImage b)
        {
            InitializeComponent();
            image = b;
            //double x = this.Height;
            //image.Height = x;
            //image.Width = Width;
            currI   = 0;
            gameWon = false;
            if (image != null)
            {
                game            = new MiniGame(image, 2, 2);
                game.GameCanvas = canvas;
                game.fieldFill();

                myBlurEffect                 = new BlurBitmapEffect();
                myBlurEffect.Radius          = 50;
                game.GameCanvas.BitmapEffect = myBlurEffect;
            }
        }
Exemple #14
0
        private void OnMoveMade(object sender, HandledEventArgs e)
        {
            // Blur or unblur based on whether the move was a valid one.
            BlurBitmapEffect blur = (BlurBitmapEffect)ControlPanel.BitmapEffect;

            if (blur != null)
            {
                if (e.Handled)
                {
                    if (blur.Radius >= 2.0)
                    {
                        blur.Radius -= 2.0;
                    }
                    StatusLabel.Content = "";
                }
                else
                {
                    blur.Radius        += 2.0;
                    StatusLabel.Content = "Bad Move!";
                }
            }
        }
Exemple #15
0
        public RenderTargetBitmap CreateBitmap(string text, Typeface typeface, double fontSize)
        {
            RenderTargetBitmap renderTargetBitmap = (RenderTargetBitmap)null;

            try
            {
                Pen                    pen                = this.CreatePen();
                Brush                  brush              = this.CreateBrush();
                FormattedText          formattedText      = new FormattedText(text, CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface, fontSize, (Brush)Brushes.White);
                Geometry               geometry           = formattedText.BuildGeometry(new System.Windows.Point(50.0, 50.0));
                DrawingVisual          drawingVisual      = new DrawingVisual();
                DrawingContext         drawingContext     = drawingVisual.RenderOpen();
                BitmapEffectGroup      bitmapEffectGroup  = new BitmapEffectGroup();
                DropShadowBitmapEffect shadowBitmapEffect = new DropShadowBitmapEffect();
                OuterGlowBitmapEffect  glowBitmapEffect   = new OuterGlowBitmapEffect();
                BevelBitmapEffect      bevelBitmapEffect  = new BevelBitmapEffect();
                BlurBitmapEffect       blurBitmapEffect   = new BlurBitmapEffect();
                EmbossBitmapEffect     embossBitmapEffect = new EmbossBitmapEffect();

                /*      foreach (Nubik.Tools.SpriteFont.Enums.Effect effect in (IEnumerable<Nubik.Tools.SpriteFont.Enums.Effect>)GlobalObject<Settings>.Instance.EffectOrder.Values)
                 *    {
                 *        if (effect == Nubik.Tools.SpriteFont.Enums.Effect.DropShadow && GlobalObject<Settings>.Instance.DropShadow.IsEnabled)
                 *            bitmapEffectGroup.Children.Add((BitmapEffect)shadowBitmapEffect);
                 *        else if (effect == Nubik.Tools.SpriteFont.Enums.Effect.OuterGlow && GlobalObject<Settings>.Instance.OuterGlow.IsEnabled)
                 *            bitmapEffectGroup.Children.Add((BitmapEffect)glowBitmapEffect);
                 *        else if (effect == Nubik.Tools.SpriteFont.Enums.Effect.Bevel && GlobalObject<Settings>.Instance.Bevel.IsEnabled)
                 *            bitmapEffectGroup.Children.Add((BitmapEffect)bevelBitmapEffect);
                 *        else if (effect == Nubik.Tools.SpriteFont.Enums.Effect.Blur && GlobalObject<Settings>.Instance.Blur.IsEnabled)
                 *            bitmapEffectGroup.Children.Add((BitmapEffect)blurBitmapEffect);
                 *        else if (effect == Nubik.Tools.SpriteFont.Enums.Effect.Emboss && GlobalObject<Settings>.Instance.Emboss.IsEnabled)
                 *            bitmapEffectGroup.Children.Add((BitmapEffect)embossBitmapEffect);
                 *    }*/
                drawingContext.PushEffect((BitmapEffect)bitmapEffectGroup, (BitmapEffectInput)null);
                drawingContext.DrawGeometry(brush, pen, geometry);
                drawingContext.Close();
                if (double.IsInfinity(geometry.Bounds.X) || double.IsInfinity(geometry.Bounds.Y))
                {
                    return(renderTargetBitmap);
                }
                int pixelWidth  = 0;
                int pixelHeight = 0;
                try
                {
                    pixelWidth  = Convert.ToInt32(geometry.Bounds.X + geometry.Bounds.Width) + 50;
                    pixelHeight = Convert.ToInt32(geometry.Bounds.Y + geometry.Bounds.Height) + 50;
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                renderTargetBitmap = new RenderTargetBitmap(pixelWidth, pixelHeight, 96.0, 96.0, PixelFormats.Pbgra32);
                renderTargetBitmap.Render((Visual)drawingVisual);
                try
                {
                    renderTargetBitmap.Freeze();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
            return(renderTargetBitmap);
        }
        private void createMultipleDrawingGroupExample(Panel examplePanel)
        {
            // <SnippetGraphicsMMMultipleDrawingGroupsExample>

            // Create a DrawingGroup.
            DrawingGroup mainGroup = new DrawingGroup();

            //
            // Create a GeometryDrawing
            //
            GeometryDrawing ellipseDrawing =
                new GeometryDrawing(
                    new SolidColorBrush(Color.FromArgb(102, 181, 243, 20)),
                    new Pen(Brushes.Black, 4),
                    new EllipseGeometry(new Point(50, 50), 50, 50)
                    );

            //
            // Use a DrawingGroup to apply a blur
            // bitmap effect to the drawing.
            //
            DrawingGroup blurGroup = new DrawingGroup();

            blurGroup.Children.Add(ellipseDrawing);
            BlurBitmapEffect blurEffect = new BlurBitmapEffect();

            blurEffect.Radius      = 5;
            blurGroup.BitmapEffect = blurEffect;

            // Add the DrawingGroup to the main DrawingGroup.
            mainGroup.Children.Add(blurGroup);

            //
            // Create an ImageDrawing.
            //
            ImageDrawing kiwiPictureDrawing =
                new ImageDrawing(
                    new BitmapImage(new Uri(@"sampleImages\kiwi.png", UriKind.Relative)),
                    new Rect(50, 50, 100, 100));

            //
            // Use a DrawingGroup to apply an opacity mask
            // and a bevel.
            //
            DrawingGroup maskedAndBeveledGroup = new DrawingGroup();

            maskedAndBeveledGroup.Children.Add(kiwiPictureDrawing);

            // Create an opacity mask.
            RadialGradientBrush rgBrush = new RadialGradientBrush();

            rgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 0.55));
            rgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(255, 0, 0, 0), 0.65));
            rgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 0.75));
            rgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(255, 0, 0, 0), 0.80));
            rgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(0, 0, 0, 0), 0.90));
            rgBrush.GradientStops.Add(new GradientStop(Color.FromArgb(255, 0, 0, 0), 1.0));
            maskedAndBeveledGroup.OpacityMask = rgBrush;

            // Apply a bevel.
            maskedAndBeveledGroup.BitmapEffect = new BevelBitmapEffect();

            // Add the DrawingGroup to the main group.
            mainGroup.Children.Add(maskedAndBeveledGroup);

            //
            // Create another GeometryDrawing.
            //
            GeometryDrawing ellipseDrawing2 =
                new GeometryDrawing(
                    new SolidColorBrush(Color.FromArgb(102, 181, 243, 20)),
                    new Pen(Brushes.Black, 4),
                    new EllipseGeometry(new Point(150, 150), 50, 50)
                    );

            // Add the DrawingGroup to the main group.
            mainGroup.Children.Add(ellipseDrawing2);

            // </SnippetGraphicsMMMultipleDrawingGroupsExample>

            //
            // Use a DrawingImage and an Image to display the DrawingGroup.
            //
            DrawingImage drawingImageSource = new DrawingImage(mainGroup);

            // Freeze the DrawingImage for performance benefits.
            drawingImageSource.Freeze();

            Image anImage = new Image();

            anImage.Source              = drawingImageSource;
            anImage.Stretch             = Stretch.None;
            anImage.HorizontalAlignment = HorizontalAlignment.Left;

            Border imageBorder = new Border();

            imageBorder.BorderBrush         = Brushes.Gray;
            imageBorder.BorderThickness     = new Thickness(1);
            imageBorder.HorizontalAlignment = HorizontalAlignment.Left;
            imageBorder.Margin = new Thickness(10);
            imageBorder.Child  = anImage;

            examplePanel.Children.Add(imageBorder);
        }
Exemple #17
0
        public ReflectionExample()
        {
            // Create a name scope for the page.
            NameScope.SetNameScope(this, new NameScope());

            this.Background = Brushes.Black;
            StackPanel myStackPanel = new StackPanel();

            myStackPanel.Margin = new Thickness(50);

            Border myReflectedBorder = new Border();

            this.RegisterName("ReflectedVisual", myReflectedBorder);

            // Create a gradient background for the border.
            GradientStop firstStop = new GradientStop();

            firstStop.Offset = 0.0;
            Color firstStopColor = new Color();

            firstStopColor.R = 204;
            firstStopColor.G = 204;
            firstStopColor.B = 255;
            firstStopColor.A = 255;
            firstStop.Color  = firstStopColor;
            GradientStop secondStop = new GradientStop();

            secondStop.Offset = 1.0;
            secondStop.Color  = Colors.White;

            GradientStopCollection myGradientStopCollection = new GradientStopCollection();

            myGradientStopCollection.Add(firstStop);
            myGradientStopCollection.Add(secondStop);

            LinearGradientBrush myLinearGradientBrush = new LinearGradientBrush();

            myLinearGradientBrush.StartPoint    = new Point(0, 0.5);
            myLinearGradientBrush.EndPoint      = new Point(1, 0.5);
            myLinearGradientBrush.GradientStops = myGradientStopCollection;

            myReflectedBorder.Background = myLinearGradientBrush;

            // Add contents to the border.
            StackPanel borderStackPanel = new StackPanel();

            borderStackPanel.Orientation = Orientation.Horizontal;
            borderStackPanel.Margin      = new Thickness(10);

            TextBlock myTextBlock = new TextBlock();

            myTextBlock.TextWrapping = TextWrapping.Wrap;
            myTextBlock.Width        = 200;
            myTextBlock.Text         = "Lorem ipsum dolor sit amet, consectetuer adipiscing elit." +
                                       " Suspendisse vel ante. Donec luctus tortor sit amet est." +
                                       " Nullam pulvinar odio et wisi." +
                                       " Pellentesque quis magna. Sed pellentesque." +
                                       " Nulla euismod." +
                                       "Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.";

            borderStackPanel.Children.Add(myTextBlock);

            StackPanel ellipseStackPanel = new StackPanel();

            Ellipse ellipse1 = new Ellipse();

            ellipse1.Margin = new Thickness(10);
            ellipse1.Height = 50;
            ellipse1.Width  = 50;
            ellipse1.Fill   = Brushes.Black;
            ellipseStackPanel.Children.Add(ellipse1);
            Ellipse ellipse2 = new Ellipse();

            ellipse2.Margin = new Thickness(10);
            ellipse2.Height = 50;
            ellipse2.Width  = 50;
            ellipse2.Fill   = Brushes.Black;
            ellipseStackPanel.Children.Add(ellipse2);
            Ellipse ellipse3 = new Ellipse();

            ellipse3.Margin = new Thickness(10);
            ellipse3.Height = 50;
            ellipse3.Width  = 50;
            ellipse3.Fill   = Brushes.Black;
            ellipseStackPanel.Children.Add(ellipse3);
            borderStackPanel.Children.Add(ellipseStackPanel);

            myReflectedBorder.Child = borderStackPanel;

            // Create divider rectangle
            Rectangle dividerRectangle = new Rectangle();

            dividerRectangle.Height = 1;
            dividerRectangle.Fill   = Brushes.Gray;
            dividerRectangle.HorizontalAlignment = HorizontalAlignment.Stretch;

            // Create the object to contain the reflection.
            Rectangle reflectionRectangle = new Rectangle();

            // Bind the height of the rectangle to the border height.
            Binding heightBinding = new Binding();

            heightBinding.ElementName = "ReflectedVisual";
            heightBinding.Path        = new PropertyPath(Rectangle.HeightProperty);
            BindingOperations.SetBinding(reflectionRectangle, Rectangle.HeightProperty, heightBinding);

            // Bind the width of the rectangle to the border width.
            Binding widthBinding = new Binding();

            widthBinding.ElementName = "ReflectedVisual";
            widthBinding.Path        = new PropertyPath(Rectangle.WidthProperty);
            BindingOperations.SetBinding(reflectionRectangle, Rectangle.WidthProperty, widthBinding);

            // Creates the reflection.
            VisualBrush myVisualBrush = new VisualBrush();

            myVisualBrush.Opacity = 0.75;
            myVisualBrush.Stretch = Stretch.None;
            Binding reflectionBinding = new Binding();

            reflectionBinding.ElementName = "ReflectedVisual";
            BindingOperations.SetBinding(myVisualBrush, VisualBrush.VisualProperty, reflectionBinding);

            ScaleTransform myScaleTransform = new ScaleTransform();

            myScaleTransform.ScaleX = 1;
            myScaleTransform.ScaleY = -1;
            TranslateTransform myTranslateTransform = new TranslateTransform();

            myTranslateTransform.Y = 1;

            TransformGroup myTransformGroup = new TransformGroup();

            myTransformGroup.Children.Add(myScaleTransform);
            myTransformGroup.Children.Add(myTranslateTransform);

            myVisualBrush.RelativeTransform = myTransformGroup;

            reflectionRectangle.Fill = myVisualBrush;

            // Create a gradient background for the border.
            GradientStop firstStop2 = new GradientStop();

            firstStop2.Offset = 0.0;
            Color c1 = new Color();

            c1.R             = 0;
            c1.G             = 0;
            c1.B             = 0;
            c1.A             = 255;
            firstStop2.Color = c1;
            GradientStop secondStop2 = new GradientStop();

            secondStop2.Offset = 0.5;
            Color c2 = new Color();

            c2.R             = 0;
            c2.G             = 0;
            c2.B             = 0;
            c2.A             = 51;
            firstStop2.Color = c2;
            GradientStop thirdStop = new GradientStop();

            thirdStop.Offset = 0.75;
            Color c3 = new Color();

            c3.R            = 0;
            c3.G            = 0;
            c3.B            = 0;
            c3.A            = 0;
            thirdStop.Color = c3;

            GradientStopCollection myGradientStopCollection2 = new GradientStopCollection();

            myGradientStopCollection2.Add(firstStop2);
            myGradientStopCollection2.Add(secondStop2);
            myGradientStopCollection2.Add(thirdStop);

            LinearGradientBrush myLinearGradientBrush2 = new LinearGradientBrush();

            myLinearGradientBrush2.StartPoint    = new Point(0.5, 0);
            myLinearGradientBrush2.EndPoint      = new Point(0.5, 1);
            myLinearGradientBrush2.GradientStops = myGradientStopCollection2;

            reflectionRectangle.OpacityMask = myLinearGradientBrush2;

            BlurBitmapEffect myBlurBitmapEffect = new BlurBitmapEffect();

            myBlurBitmapEffect.Radius = 1.5;

            reflectionRectangle.BitmapEffect = myBlurBitmapEffect;

            myStackPanel.Children.Add(myReflectedBorder);
            myStackPanel.Children.Add(dividerRectangle);
            myStackPanel.Children.Add(reflectionRectangle);
            this.Content = myStackPanel;
        }
        public BitmapEffectExample()
        {
            //
            // Create a DrawingGroup
            // that has no BitmapEffect
            //
            PathFigure pLineFigure = new PathFigure();

            pLineFigure.StartPoint = new Point(25, 25);
            PolyLineSegment pLineSegment = new PolyLineSegment();

            pLineSegment.Points.Add(new Point(0, 50));
            pLineSegment.Points.Add(new Point(25, 75));
            pLineSegment.Points.Add(new Point(50, 50));
            pLineSegment.Points.Add(new Point(25, 25));
            pLineSegment.Points.Add(new Point(25, 0));
            pLineFigure.Segments.Add(pLineSegment);
            PathGeometry pGeometry = new PathGeometry();

            pGeometry.Figures.Add(pLineFigure);

            GeometryDrawing drawing1 = new GeometryDrawing(
                Brushes.Lime,
                new Pen(Brushes.Black, 10),
                pGeometry
                );

            GeometryDrawing drawing2 = new GeometryDrawing(
                Brushes.Lime,
                new Pen(Brushes.Black, 2),
                new EllipseGeometry(new Point(10, 10), 5, 5)
                );

            // Create a DrawingGroup
            DrawingGroup drawingGroupWithoutBitmapEffect = new DrawingGroup();

            drawingGroupWithoutBitmapEffect.Children.Add(drawing1);
            drawingGroupWithoutBitmapEffect.Children.Add(drawing2);

            // Use an Image control and a DrawingImage to
            // display the drawing.
            DrawingImage drawingImage01 = new DrawingImage(drawingGroupWithoutBitmapEffect);

            // Freeze the DrawingImage for performance benefits.
            drawingImage01.Freeze();

            Image image01 = new Image();

            image01.Source              = drawingImage01;
            image01.Stretch             = Stretch.None;
            image01.HorizontalAlignment = HorizontalAlignment.Left;

            //
            // Create another DrawingGroup and apply
            // a blur effect to it.
            //

            // Create a clone of the first DrawingGroup.
            DrawingGroup drawingGroupWithBitmapEffect =
                drawingGroupWithoutBitmapEffect.Clone();

            // Create a blur effect.
            BlurBitmapEffect blurEffect = new BlurBitmapEffect();

            blurEffect.Radius = 3.0;

            // Apply it to the drawing group.
            drawingGroupWithBitmapEffect.BitmapEffect = blurEffect;

            // Use another Image control and DrawingImage
            // to display the drawing.
            DrawingImage drawingImage02 = new DrawingImage(drawingGroupWithBitmapEffect);

            // Freeze the DrawingImage for performance benefits.
            drawingImage02.Freeze();

            Image image02 = new Image();

            image02.Source              = drawingImage02;
            image02.Stretch             = Stretch.None;
            image02.HorizontalAlignment = HorizontalAlignment.Left;

            // Create borders around the images and add them to the
            // page.
            Border border01 = new Border();

            border01.BorderBrush       = Brushes.Gray;
            border01.BorderThickness   = new Thickness(1);
            border01.VerticalAlignment = VerticalAlignment.Top;
            border01.Margin            = new Thickness(10);
            border01.Child             = image01;

            Border border02 = new Border();

            border02.BorderBrush       = Brushes.Gray;
            border02.BorderThickness   = new Thickness(1);
            border02.VerticalAlignment = VerticalAlignment.Top;
            border02.Margin            = new Thickness(50, 10, 10, 10);
            border02.Child             = image02;

            StackPanel mainPanel = new StackPanel();

            mainPanel.Orientation         = Orientation.Horizontal;
            mainPanel.HorizontalAlignment = HorizontalAlignment.Left;
            mainPanel.VerticalAlignment   = VerticalAlignment.Top;
            mainPanel.Children.Add(border01);
            mainPanel.Children.Add(border02);

            //
            // Use a DrawingBrush to create a checkered background for the page.
            //
            GeometryDrawing backgroundSquareDrawing =
                new GeometryDrawing(
                    Brushes.White,
                    null,
                    new RectangleGeometry(new Rect(0, 0, 1, 1)));
            GeometryGroup twoRectangles = new GeometryGroup();

            twoRectangles.Children.Add(new RectangleGeometry(new Rect(0, 0, 0.5, 0.5)));
            twoRectangles.Children.Add(new RectangleGeometry(new Rect(0.5, 0.5, 0.5, 0.5)));
            SolidColorBrush squaresBrush =
                new SolidColorBrush(Color.FromArgb(102, 204, 204, 204));

            squaresBrush.Opacity = 0.4;
            GeometryDrawing checkerDrawing =
                new GeometryDrawing(
                    squaresBrush,
                    null,
                    twoRectangles);
            DrawingGroup checkerDrawings = new DrawingGroup();

            checkerDrawings.Children.Add(backgroundSquareDrawing);
            checkerDrawings.Children.Add(checkerDrawing);
            DrawingBrush checkerBrush = new DrawingBrush(checkerDrawings);

            checkerBrush.Viewport      = new Rect(0, 0, 10, 10);
            checkerBrush.ViewportUnits = BrushMappingMode.Absolute;
            checkerBrush.TileMode      = TileMode.Tile;
            checkerBrush.Freeze();

            this.Background = checkerBrush;
            this.Content    = mainPanel;
        }
Exemple #19
0
        public MultipleEffectAnimationExample()
        {
            // Create a NameScope for this page so that
            // Storyboards can be used.
            NameScope.SetNameScope(this, new NameScope());

            Button myButton = new Button();

            myButton.Content = "Click Me to Animate Drop Shadow!";
            myButton.Margin  = new Thickness(50);
            myButton.Width   = 300;

            ScaleTransform myScaleTransform = new ScaleTransform();

            // Assign the ScaleTransform a name so that
            // it can be targeted by a Storyboard.
            this.RegisterName("MyAnimatedScaleTransform", myScaleTransform);

            myScaleTransform.ScaleX  = 1;
            myScaleTransform.ScaleY  = 1;
            myScaleTransform.CenterX = 100;

            // Associate the transform to the button.
            myButton.RenderTransform = myScaleTransform;

            // Create BitmapEffects that will be animated.
            BlurBitmapEffect myBlurBitmapEffect = new BlurBitmapEffect();

            // Assign the BlurBitmapEffect a name so that
            // it can be targeted by a Storyboard.
            this.RegisterName("myBlurBitmapEffect", myBlurBitmapEffect);

            myBlurBitmapEffect.Radius     = 0;
            myBlurBitmapEffect.KernelType = KernelType.Box;

            DropShadowBitmapEffect myDropShadowBitmapEffect = new DropShadowBitmapEffect();

            // Assign the BlurBitmapEffect a name so that
            // it can be targeted by a Storyboard.
            this.RegisterName("myDropShadowBitmapEffect", myDropShadowBitmapEffect);

            myDropShadowBitmapEffect.Color       = Colors.Black;
            myDropShadowBitmapEffect.ShadowDepth = 0;

            BitmapEffectGroup myBitmapEffectGroup = new BitmapEffectGroup();

            myBitmapEffectGroup.Children.Add(myBlurBitmapEffect);
            myBitmapEffectGroup.Children.Add(myDropShadowBitmapEffect);

            myButton.BitmapEffect = myBitmapEffectGroup;

            // Create an animation to animate the ScaleX property of the
            // ScaleTransform applied to the button.
            DoubleAnimation myDoubleAnimationScaleX = new DoubleAnimation();

            myDoubleAnimationScaleX.Duration    = TimeSpan.FromSeconds(1);
            myDoubleAnimationScaleX.AutoReverse = true;
            myDoubleAnimationScaleX.To          = 5;

            // Set the animation to target the ScaleX property of
            // the object named "MyAnimatedScaleTransform. This makes the
            // button get larger and smaller on the horizontal axis."
            Storyboard.SetTargetName(myDoubleAnimationScaleX, "MyAnimatedScaleTransform");
            Storyboard.SetTargetProperty(
                myDoubleAnimationScaleX, new PropertyPath(ScaleTransform.ScaleXProperty));

            // Set the animation to target the ScaleY property of
            // the object named "MyAnimatedScaleTransform. This makes the
            // button get larger and smaller on the vertical axis."
            DoubleAnimation myDoubleAnimationScaleY = new DoubleAnimation();

            myDoubleAnimationScaleY.Duration    = TimeSpan.FromSeconds(1);
            myDoubleAnimationScaleY.AutoReverse = true;
            myDoubleAnimationScaleY.To          = 5;

            Storyboard.SetTargetName(myDoubleAnimationScaleY, "MyAnimatedScaleTransform");
            Storyboard.SetTargetProperty(
                myDoubleAnimationScaleY, new PropertyPath(ScaleTransform.ScaleYProperty));

            // Set the animation to target the ShadowDepth property of
            // the object named "myDropShadowBitmapEffect. This makes the
            // button appear to be lifting off the screen as its shadow moves."
            DoubleAnimation myDoubleAnimationShadowDepth = new DoubleAnimation();

            myDoubleAnimationShadowDepth.Duration    = TimeSpan.FromSeconds(1);
            myDoubleAnimationShadowDepth.AutoReverse = true;
            myDoubleAnimationShadowDepth.From        = 0;
            myDoubleAnimationShadowDepth.To          = 50;

            Storyboard.SetTargetName(myDoubleAnimationShadowDepth, "myDropShadowBitmapEffect");
            Storyboard.SetTargetProperty(
                myDoubleAnimationShadowDepth, new PropertyPath(DropShadowBitmapEffect.ShadowDepthProperty));

            // Animate the blur to make the object appear to
            // be coming out of the screen. Use a spline key
            // frame to make the blur animate suddenly at the
            // very end of the animation.
            DoubleAnimationUsingKeyFrames myDoubleAnimationUsingKeyFrames = new DoubleAnimationUsingKeyFrames();

            myDoubleAnimationUsingKeyFrames.AutoReverse = true;

            // Set the animation to target the Radius property
            // of the object named "myBlurBitmapEffect."
            Storyboard.SetTargetName(myDoubleAnimationUsingKeyFrames, "myBlurBitmapEffect");
            Storyboard.SetTargetProperty(
                myDoubleAnimationUsingKeyFrames, new PropertyPath(BlurBitmapEffect.RadiusProperty));
            myDoubleAnimationUsingKeyFrames.KeyFrames.Add(
                new SplineDoubleKeyFrame(
                    30,                                            // Target value (KeyValue)
                    KeyTime.FromTimeSpan(TimeSpan.FromSeconds(1)), // KeyTime
                    new KeySpline(0.6, 0.0, 0.9, 0.0)              // KeySpline
                    )
                );

            // Create a storyboard and add the animations to it.
            Storyboard myStoryboard = new Storyboard();

            myStoryboard.Children.Add(myDoubleAnimationScaleX);
            myStoryboard.Children.Add(myDoubleAnimationScaleY);
            myStoryboard.Children.Add(myDoubleAnimationShadowDepth);
            myStoryboard.Children.Add(myDoubleAnimationUsingKeyFrames);

            // Start the storyboard when button is clicked.
            myButton.Click += delegate(object sender, RoutedEventArgs e)
            {
                myStoryboard.Begin(this);
            };

            StackPanel myStackPanel = new StackPanel();

            myStackPanel.Children.Add(myButton);
            this.Content = myStackPanel;
        }