Images

Presentation.Images 属性

返回演示文稿中所有图像的集合。只读 IImageCollection

public IImageCollection Images { get; }

示例

以下示例演示如何将图像作为 BLOB 添加到 PowerPoint 演示文稿中。

[C#]
string pathToLargeImage = "large_image.jpg";
// 创建一个新的演示文稿,将在其中添加图像。
using (Presentation pres = new Presentation())
{
	using (FileStream fileStream = new FileStream(pathToLargeImage, FileMode.Open))
	{
		// 让我们将图像添加到演示文稿中 - 我们选择 KeepLocked 行为,因为我们
		// 不打算访问 "largeImage.png" 文件。
		IPPImage img = pres.Images.AddImage(fileStream, LoadingStreamBehavior.KeepLocked);
		pres.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 0, 0, 300, 200, img);
		// 保存演示文稿。在输出大型演示文稿时,内存消耗
		// 在 pres 对象的生命周期内保持较低
		pres.Save("presentationWithLargeImage.pptx", SaveFormat.Pptx);
	}
}

以下示例在 PowerPoint 演示文稿中的图像上添加超链接。

[C#]
using (Presentation pres = new Presentation())
{
    // 向演示文稿添加图像
    IPPImage image = pres.Images.AddImage(File.ReadAllBytes("image.png"));
    // 基于先前添加的图像在幻灯片 1 上创建图片框
    IPictureFrame pictureFrame = pres.Slides[0].Shapes.AddPictureFrame(ShapeType.Rectangle, 10, 10, 100, 100, image);
    pictureFrame.HyperlinkClick = new Hyperlink("https://www.aspose.com/");
    pictureFrame.HyperlinkClick.Tooltip = "超过 70% 的财富 100 强公司信任 Aspose API";
    pres.Save("pres-out.pptx", SaveFormat.Pptx);
}

另请参见