前面我们介绍了如何使用spire.presentation。同时还支持将幻灯片中的单个元素(如图表、表格和形状)导出为图像。本文将详细介绍如何使用shapelist.saveasimage(int shapeindex)方法将幻灯片中的图表和表格单独保存为图片。
首先,请查看幻灯片示例,该幻灯片包含text shape, chart和shape:
c#
//加载powerpoint示例文档
presentation ppt = new presentation();
ppt.loadfromfile("sample.pptx");
//将图表保存为图片
image image = ppt.slides[0].shapes.saveasimage(1);
image.save("chart.png", system.drawing.imaging.imageformat.png);
//将图形保存为图片
image = ppt.slides[0].shapes.saveasimage(2);
image.save("shape.png", system.drawing.imaging.imageformat.png);
vb.net
'加载powerpoint示例文档
dim ppt as new presentation()
ppt.loadfromfile("sample.pptx")
'将图表保存为图片
dim image as image = ppt.slides(0).shapes.saveasimage(1)
image.save("chart.png", system.drawing.imaging.imageformat.png)
'将图形保存为图片
image = ppt.slides(0).shapes.saveasimage(2)
image.save("shape.png", system.drawing.imaging.imageformat.png)