Free Spire.Presentation for .NET (免费版)
Visual Studio
下载安装该类库后,注意引用Spire.Presentation.dll到程序,(dll文件可在安装路径下的Bin文件夹中获取)
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'); } }}
调试运行程序,生成文档,查看图片阴影效果(如下图)