PPT设计中为了美化图片效果,有时需要为图片添加阴影。本文将介绍如何使用Spire.Presentation为PPT中的图片设置阴影效果。
//创建Presentation实例,获取第一张幻灯片
Presentation ppt = new Presentation();
ISlide slide = ppt.Slides[0];
//获取图片地址及长宽
string imagePath = "image.png";
Image image = Image.FromFile(imagePath);
float width = (float)image.Width/2;
float height = (float)image.Height/2;
//将图片添加至指定位置
RectangleF rect = new RectangleF(50, 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(300, 80, 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 = 20;
innerShadow.Direction = 0;
innerShadow.Distance = 3;
innerShadow.ColorFormat.Color = Color.Black;
//在第二张图片上应用阴影效果
shape.EffectDag.InnerShadowEffect = innerShadow;
//保存文档
ppt.SaveToFile("ImageShadow.pptx", FileFormat.Pptx2010);