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; }
//========================================================================== public BitmapEffect ToBitmapEffect() { if (Document.Options.IgnoreEffects) { return(null); } BitmapEffectGroup bitmap_effect_group = new BitmapEffectGroup(); foreach (SvgFilterEffectBaseElement filter_effect in FilterEffects) { BitmapEffect bitmap_effect = filter_effect.ToBitmapEffect(); if (bitmap_effect != null) { bitmap_effect_group.Children.Add(bitmap_effect); } } if (bitmap_effect_group.Children.Count == 0) { return(null); } return(bitmap_effect_group); }
public BitmapEffect GetBitmapEffect() { var beg = new BitmapEffectGroup(); foreach (FilterBaseFe element in this.Elements) { beg.Children.Add(element.GetBitmapEffect()); } return(beg); }
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); }
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; }