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

发布于 2024-12-13 19:46:01 字数 1562 浏览 0 评论 0原文

我有一个 .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
    }

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

I have a Windows forms app in .Net 4.0. I work in C#.
I want to grab an image from a given slide in a .pptx file.

This code gets every image on the slide:

 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
    }

But, how to convert slidePart to an image which will be shown in my Windows form (in imageList or something similar)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨洒年华 2024-12-20 19:46:01

找到了一个办法:

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());

Found a way:

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());
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文