在PowerPoint中,我们可以给幻灯片中的图片添加超链接,播放幻灯片时点击图片就能跳转到指定的网址。本文将介绍如何使用Spire.Presentation组件给PowerPoint文档中的图片添加超链接和获取图片的超链接。
给图片添加超链接
C#
//创建Presentation实例
Presentation presentation = new Presentation();
//获取第一张幻灯片
ISlide slide = presentation.Slides[0];
RectangleF rect = new RectangleF(50, 300, 100, 100);
//添加图片到幻灯片
IEmbedImage image = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, @"logo.png", rect);
//添加超链接到图片
ClickHyperlink hyperlink = new ClickHyperlink("https://www.e-iceblue.com");
image.Click = hyperlink;
//保存文档
presentation.SaveToFile("ImageHyperLink.pptx", FileFormat.Pptx2010);
VB.NET
'创建Presentation实例
Dim presentation As New Presentation()
'获取第一张幻灯片
Dim slide As ISlide = presentation.Slides(0)
Dim rect As New RectangleF(50, 300, 100, 100)
'添加图片到幻灯片
Dim image As IEmbedImage = slide.Shapes.AppendEmbedImage(ShapeType.Rectangle, "logo.png", rect)
'添加超链接到图片
Dim hyperlink As New ClickHyperlink("https://www.e-iceblue.com")
image.Click = hyperlink
'保存文档
presentation.SaveToFile("ImageHyperLink.pptx", FileFormat.Pptx2010)
效果图:
获取图片的超链接
C#
//创建Presentation实例
Presentation presentation = new Presentation();
//加载PowerPoint文档
presentation.LoadFromFile("ImageHyperLink.pptx");
//获取第一张幻灯片
ISlide slide = presentation.Slides[0];
//获取幻灯片中图片的超链接
string hyperlink = (slide.Shapes[0] as IEmbedImage).Click.Address;
File.WriteAllText("hyperlinks.txt", hyperlink);
VB.NET
'创建Presentation实例
Dim presentation As New Presentation()
'加载PowerPoint文档
presentation.LoadFromFile("ImageHyperLink.pptx")
'获取第一张幻灯片
Dim slide As ISlide = presentation.Slides(0)
'获取幻灯片中图片的超链接
Dim hyperlink As String = TryCast(slide.Shapes(0), IEmbedImage).Click.Address
File.WriteAllText("hyperlinks.txt", hyperlink)
效果图: