// Add Bevel effect.
        void OnLoadEmbossImage(object sender, RoutedEventArgs args)
        {
            // Get a reference to the Button.
            Image myImage = (Image)sender;

            // Initialize a new BevelBitmapEffect that will be applied
            // to the Button.
            EmbossBitmapEffect myEmbossEffect = new EmbossBitmapEffect();

            // The LightAngle determines from what direction the artificial
            // light is cast upon the embossed object which effects shadowing.
            // The valid range is from 0-360 (degrees)with 0 specifying the
            // right-hand side of the object and successive values moving
            // counter-clockwise around the object.
            // Set the LightAngle to 320 degrees (lower right side).
            myEmbossEffect.LightAngle = 320;

            // The Relief property determines the amount of relief of the emboss.
            // The valid range of values is 0-1 with 0 having the least relief and
            // 1 having the most. The default value is 0.44.
            myEmbossEffect.Relief = 0.8;

            // Apply the bitmap effect to the Image.
            myImage.BitmapEffect = myEmbossEffect;
        }
Beispiel #2
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);
        }