Spire.Presentation for .NET 版本 2.9
Visual Studio
下载安装该类库后,注意添加引用Spire.Presentation.dll到项目程序,dll文件可在安装路径下的Bin文件夹中获取。
using Spire.Presentation;using Spire.Presentation.Drawing;using System.Drawing;namespace SetImgTransparancy_PPT{ class Program { static void Main(string[] args) { //创建PowerPoint文档 Presentation presentation = new Presentation(); //加载图片到Image对象 string imagePath = 'EX1.png'; Image image = Image.FromFile(imagePath); //获取图片长宽 float width = image.Width; float height = image.Height; //添加图形到幻灯片 RectangleF rect = new RectangleF(50, 50, width, height); IAutoShape shape = presentation.Slides[0].Shapes.AppendShape(ShapeType.Rectangle, rect); shape.Line.FillType = FillFormatType.None; //用图片填充图形 shape.Fill.FillType = FillFormatType.Picture; shape.Fill.PictureFill.Picture.Url = imagePath; shape.Fill.PictureFill.FillType = PictureFillType.Stretch; //设置图片透明度(0-100) shape.Fill.PictureFill.Picture.Transparency = 50; //保存并打开文档 presentation.SaveToFile('output.pptx', FileFormat.Pptx2010); System.Diagnostics.Process.Start('output.pptx'); } }}
完成代码后,调试运行程序,生成文档,如下: