News Category

Apply Shadow Effect to Shape in PowerPoint in C#

2018-03-19 05:57:00 Written by  support iceblue
Rate this item
(0 votes)

Shadows make your shapes or pictures especially with transparent background pop out of your slide. They make flat 2 dimensional graphics look like 3 dimensional graphics. This article will show you how we can apply shadow effects to shapes and pictures in PowerPoint using Spire.Presentation.

Apply Shadow Effect to Shape

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace ApplyShadoweffect
{

    class Program
    {

        static void Main(string[] args)
        {
            {
                //Create a Presentation object and get the first slide.
                Presentation ppt = new Presentation();
                ISlide slide = ppt.Slides[0];

                //Add a shape to slide.
                RectangleF rect = new RectangleF(30, 80, 300, 120);
                IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, rect);
                shape.Fill.FillType = FillFormatType.Solid;
                shape.Fill.SolidColor.Color = Color.LightBlue;
                shape.Line.FillType = FillFormatType.None;
                shape.TextFrame.Text = "This demo shows how to apply shadow effect to shape.";
                shape.TextFrame.TextRange.Fill.FillType = FillFormatType.Solid;
                shape.TextFrame.TextRange.Fill.SolidColor.Color = Color.Black;

                //Create an inner shadow effect through InnerShadowEffect object. 
                InnerShadowEffect innerShadow = new InnerShadowEffect();
                innerShadow.BlurRadius = 20;
                innerShadow.Direction = 0;
                innerShadow.Distance = 0;
                innerShadow.ColorFormat.Color = Color.Black;

                //Apply the shadow effect to shape.
                shape.EffectDag.InnerShadowEffect = innerShadow;

                //Save to file.
                ppt.SaveToFile("ShadowOnShape.pptx", FileFormat.Pptx2010);

            }
        }

    }
}

Apply Shadow Effect to Shape in PowerPoint in C#

Apply Shadow Effect to Picture

using Spire.Presentation;
using Spire.Presentation.Drawing;
using System.Drawing;

namespace ApplyShadoweffect
{

    class Program
    {

        static void Main(string[] args)
        {
            {
                //Create a Presentation object and get the first slide.
                Presentation ppt = new Presentation();
                ISlide slide = ppt.Slides[0];

                //Get the picture path.
                string imagePath = "dinosaur.png";
                Image image = Image.FromFile(imagePath);
                float width = (float)image.Width / 3;
                float height = (float)image.Height / 3;

                //Add a shape to slide and fill the shape with picture.
                RectangleF rect = new RectangleF(80, 80, width, height);
                IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, rect);
                shape.Fill.FillType = FillFormatType.Picture;
                shape.Fill.PictureFill.Picture.Url = imagePath;
                shape.Fill.PictureFill.FillType = PictureFillType.Stretch;
                shape.Line.FillType = FillFormatType.None;

                //Choose a preset shadow effect.
                PresetShadow presetShadow = new PresetShadow();
                presetShadow.Preset = PresetShadowValue.BackLeftPerspective;
                presetShadow.ColorFormat.Color = Color.LightGray;

                //Apply the shadow effect to shape.
                shape.EffectDag.PresetShadowEffect = presetShadow;

                //Save to file.
                ppt.SaveToFile("ShadowOnPicture.pptx", FileFormat.Pptx2010);

            }
        }

    }
}

Apply Shadow Effect to Shape in PowerPoint in C#

Additional Info

  • tutorial_title:
Last modified on Friday, 24 September 2021 09:19