多语言展示
当前在线:103今日阅读:91今日分享:37

C# 设置图片阴影效果

在设计图片时,常通过一定方法来提升图片的设计感,达到需要的呈现效果。在PPT幻灯片中,插入的图片,也常需要进行一定的处理和操作来满足设计需要,如实现阴影效果。在本篇经验中,将分享设置图片阴影效果的方法。
工具/原料
1

Free Spire.Presentation for .NET (免费版)

2

Visual Studio

dll引用

下载安装该类库后,注意引用Spire.Presentation.dll到程序,(dll文件可在安装路径下的Bin文件夹中获取)

C# 代码示例(供参考)
1

using Spire.Presentation;using Spire.Presentation.Drawing;using System.Drawing;namespace ShadowforImg_PPT{    class Program    {        static void Main(string[] args)        {            //创建Presentation实例,并获取第一张幻灯片            Presentation ppt = new Presentation();            ISlide slide = ppt.Slides[0];            //获取图片地址及长宽            string imagePath = 'car.png';            Image image = Image.FromFile(imagePath);            float width = (float)image.Width / 2;            float height = (float)image.Height / 2;            //将图片添加至指定位置            RectangleF rect = new RectangleF(300, 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;            //在不同的位置再次添加图片            rect = new RectangleF(50, 250, width, height);            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;            //实例化InnerShadowEffect类的对象,创建阴影效果            InnerShadowEffect innerShadow = new InnerShadowEffect();            innerShadow.BlurRadius = 25;            innerShadow.Direction = 0;            innerShadow.Distance = 5;            innerShadow.ColorFormat.Color = Color.Black;            //在第二张图片上应用阴影效果            shape.EffectDag.InnerShadowEffect = innerShadow;            //保存文档            ppt.SaveToFile('ImageShadow.pptx', FileFormat.Pptx2010);            System.Diagnostics.Process.Start('ImageShadow.pptx');        }    }}

2

调试运行程序,生成文档,查看图片阴影效果(如下图)

推荐信息