gpt4 book ai didi

c# - 打开 xml 从 .pptx 文件获取图像

转载 作者:行者123 更新时间:2023-11-30 16:27:18 25 4
gpt4 key购买 nike

我在 .Net 4.0 中有一个 Windows 窗体应用程序。我在 C# 工作。我想从 .pptx 文件中的给定幻灯片中抓取图像。

此代码获取幻灯片上的每张图片:

 public static SlidePart GetSlidePart(PresentationDocument presentationDocument, int slideIndex)
{
if (presentationDocument == null)
{
throw new ArgumentNullException("presentationDocument", "GetSlidePart Method: parameter presentationDocument is null");
}

int slidesCount = CountSlides(presentationDocument);

if (slideIndex < 0 || slideIndex >= slidesCount)
{
throw new ArgumentOutOfRangeException("slideIndex", "GetSlidePart Method: parameter slideIndex is out of range");
}

PresentationPart presentationPart = presentationDocument.PresentationPart;

if (presentationPart != null && presentationPart.Presentation != null)
{
Presentation presentation = presentationPart.Presentation;

if (presentation.SlideIdList != null)
{
var slideIds = presentation.SlideIdList.ChildElements;

if (slideIndex < slideIds.Count)
{
string slidePartRelationshipId = (slideIds[slideIndex] as SlideId).RelationshipId;

SlidePart slidePart = (SlidePart)presentationPart.GetPartById(slidePartRelationshipId);

return slidePart;
}
}
}

return null;// No slide found
}

但是,如何将 slidePart 转换为将显示在我的 Windows 窗体中的图像(在 imageList 或类似的东西中)?

最佳答案

找到一个方法:

SlidePart slidePart = (SlidePart)presentationPart.GetPartById(slidePartRelationshipId);

Slide slide = slidePart.Slide;
ImagePart imagePart = (ImagePart)slide.SlidePart.GetPartById("rId3");
System.Drawing.Image img = System.Drawing.Image.FromStream(imagePart.GetStream());

关于c# - 打开 xml 从 .pptx 文件获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8026705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com