在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)
效果图: