多语言展示
当前在线:153今日阅读:176今日分享:34

C# 设置PPT图片透明度

此条经验主要介绍了如何通过C#编程来设置PPT图片透明度。
工具/原料
1

Spire.Presentation for .NET 版本 2.9

2

Visual Studio

dll引用

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

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

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');        }    }}

2

完成代码后,调试运行程序,生成文档,如下:

推荐信息