概述
我们进行PPT幻灯片编辑时,可以通过设置文字或图片的阴影效果,来使幻灯片内容的呈现效果更为立体化,给人视觉上的立体感。Spire.Presentation for .NET支持图片、文字阴影效果。本文将介绍通过C#来设置PPT中文字或图片阴影效果的方法。
示例要点:
- 设置PPT文字阴影效果
- 设置PPT图片阴影效果
工具
安装后,注意在编辑代码时,添加引用Spire.Presentation.dll,dll文件可在安装路径下的Bin文件夹下获取。
C# 示例代码
【示例1】设置PPT文字阴影效果
using Spire.Presentation; using Spire.Presentation.Drawing; using System.Drawing; namespace ShadowforText_PPT { class Program { static void Main(string[] args) { //实例化Presentation类的对象,获取第一张幻灯片 Presentation presentation = new Presentation(); ISlide slide = presentation.Slides[0]; //在幻灯片指定位置绘制指定大小的矩形形状,并设置填形状填充 IAutoShape shape = slide.Shapes.AppendShape(ShapeType.Rectangle, new RectangleF(10, 10, 700,520)); shape.ShapeStyle.LineColor.Color = Color.White; string picPath = "gf.png"; shape.Fill.FillType = FillFormatType.Picture; shape.Fill.PictureFill.Picture.Url = picPath; shape.Fill.PictureFill.FillType = PictureFillType.Stretch; //shape.Fill.FillType = Spire.Presentation.Drawing.FillFormatType.Picture; //绘制文本内容到形状,并设置文本格式 shape.AppendTextFrame(" 江南逢李龟年\n 杜甫 \n 岐王宅里寻常见,崔九堂前几度闻。\n 正是江南好风景,落花时节又逢君。"); shape.TextFrame.Paragraphs[0].TextRanges[0].LatinFont = new TextFont("隶书"); shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.FillType = FillFormatType.Solid; shape.TextFrame.Paragraphs[0].TextRanges[0].Fill.SolidColor.Color = Color.Black; shape.TextFrame.Paragraphs[0].TextRanges[0].FontHeight = 38; //实例化OuterShadowEffect类的对象,设置文字阴影效果 Spire.Presentation.Drawing.OuterShadowEffect Shadow = new Spire.Presentation.Drawing.OuterShadowEffect(); //Spire.Presentation.Drawing.InnerShadowEffect Shadow = new Spire.Presentation.Drawing.InnerShadowEffect(); Shadow.BlurRadius = 0; Shadow.Direction = 50; Shadow.Distance = 10; Shadow.ColorFormat.Color = Color.Gray; shape.TextFrame.TextRange.EffectDag.OuterShadowEffect = Shadow; //shape.TextFrame.TextRange.EffectDag.InnerShadowEffect = Shadow; //保存文档并打开 presentation.SaveToFile("result.pptx", FileFormat.Pptx2010); System.Diagnostics.Process.Start("result.pptx"); } } }
PPT文字阴影添加效果:
【示例2】设置PPT图片阴影效果
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"); } } }
图片阴影效果:
(本文完)
相关推荐
项目需要做的功能。 主要是PPT 转成 图片 图片在合成 一张大图。 VS2010 + win7 包换全部DLL 文件
C# 阴影效果的文字C# 阴影效果的文字C# 阴影效果的文字C# 阴影效果的文字C# 阴影效果的文字C# 阴影效果的文字
C# 生成ppt PPt C# 生成ppt PPtC# 生成ppt PPt C# 生成ppt PPt
可以给图片绘制一个阴影的类,已经通过控制台调用测试,可以添加多种阴影
c#将ppt内容全部转换为图片,并保存至文件夹
给panel加入阴影效果。程序用c#实现,简单实用,旨在抛砖引玉。
C# 给图片加上文字或图片水印,通过使用GDI+ 给图片上加水印。实现了透明文字与透明图片水印。可设置水印位置。
在Winform取消默认边框的情况下,实现了窗体四周带阴影的效果。利用双层窗体实现,上层是普通的控件窗体,底部是绘制的窗体阴影。
阴影效果的文字C#源码
基于PPT自动播放时,离开焦点便会停止播放的缺陷。本程序通过C#实现了自动播放PPT,且离开焦点后能照样自动播放。
c# 操作 PPT,动态生成PPT,通过模板生成PPT。 c# 操作 PPT,动态生成PPT,通过模板生成PPT。
C#图片识别 pdf转图片 对图片内容进行识别 提取图片内信息
C# GDI+ 合成文字 阴影等C# GDI+ 合成文字 阴影等
c#文字生成图片 完整实例 默认输入C盘 其他调整参数自行更改
c#实现OCR图片文字识别,包含图片预处理提高识别率。支持简体繁体识别
C#图片文字提取(亲自测试过可以使用),不可以使用可以联系本人
C#124阴影效果的文字 源代码
C#教程(PPT) C#教程(PPT) C#教程(PPT) C#教程(PPT) C#教程(PPT)