IRONSOFTWAREHOME

如何在 PowerPoint 中管理图片

Ahmad Sohail
Ahmad Sohail
Updated: 2026年6月29日

多媒体元素构成了 PowerPoint 演示文稿的整体结构。 尤其是图片,它可以提供视觉背景并强化每张幻灯片上呈现的信息。有效的图像管理(无论是插入新的视觉效果、更新现有的视觉效果,还是清理过时的图形)对于保持演示文稿的专业性和可扩展性至关重要。

本指南演示了如何使用 IronPPT 以编程方式处理图像。


添加图片

要使用 IronPPT 在 PowerPoint 文档中添加图像,请创建一个新文档对象(或从现有文件加载)。 然后,从Image类创建一个引用文件的图像对象。一旦加载图像,将其添加到文档中并指定其应该显示的幻灯片编号。 从那里,可以使用Angle等属性更改图像属性。 最后,导出带有新添加图片的文档。

using IronPPT;
using IronPPT.Models;

// Create a new presentation document
var document = new PresentationDocument();

// Create and load an image from file
Image image = new Image();
image.LoadFromFile("image.jpg");

// Add image to the first slide (index 0)
var newImage = document.AddImage(image, 0);

// Rotate the image 180 degrees
newImage.Angle = 180;

// Save the presentation as a PPTX file
document.Save("adding-image.pptx");
在 PowerPoint 幻灯片中添加图像

图像属性

探索下表中的图像属性选项。

属性说明范例
高度以点为单位设置图像的高度。image.Height = 300;
宽度以点为单位设置图像的宽度。image.Width = 400;
角度以指定角度(度)旋转图像。image.Angle = 45;
职位使用 x 和 y 坐标设置幻灯片上图像的位置。image.Position = (200, 200);
FrameShape使用 ShapeType 枚举值设置图像的框架形状。image.FrameShape = IronPPT.Enums.ShapeType.RoundRectangle;

修改已添加的图像属性

将图片添加到幻灯片后,您可以修改其属性以调整外观和位置。 例如,使用Angle等属性定制图像尺寸和旋转。 调整这些设置可让您微调图像在演示文稿中的外观。

using IronPPT;
using IronPPT.Models;
using IronPPT.Enums;

// Load an existing presentation document
var document = new PresentationDocument("existing-presentation.pptx");

// Create and load an image from file
Image image = new Image();
image.LoadFromFile("image.jpg");

// Add image to the second slide (index 1)
var newImage = document.AddImage(image, 1);

// Modify image properties
newImage.Angle = 45; // Rotate the image 45 degrees
newImage.FrameShape = ShapeType.RoundRectangle; // Set the frame shape to Rounded Rectangle
newImage.Position = (180, 180); // Set the position to coordinates (180, 180)
newImage.Width = 300; // Set the width to 300 points
newImage.Height = 300; // Set the height to 300 points

// Save the modified presentation as a new PPTX file
document.Save("modifying-image-properties.pptx");
在 PowerPoint 中修改图像属性

替换图片

using IronPPT,替换图片是一项直观的任务。 首先,将演示文档和新图像加载到一个新的Image对象中。 然后,通过选择其幻灯片和索引,如Slides[0].Images[0](用于第一个幻灯片上的第一个图像)来定位您要更新的图像。 完成后,使用新图像对象调用Replace方法并导出文件。

using IronPPT;
using IronPPT.Models;

// Load an existing presentation
var document = new PresentationDocument("sample.pptx");

// Load the replacement image
Image replaceImage = new Image();
replaceImage.LoadFromFile("sample.png");

// Replace the first image found in the first slide
document.Slides[0].Images[0].Replace(replaceImage);

// Save changes (overwriting the original file)
document.Save("sample.pptx");

原文

替换 PowerPoint 幻灯片中的图像(替换前)

结果

替换 PowerPoint 幻灯片中的图像(替换后)

按索引移除图片

删除图片最简单的方法是按其索引位置删除。 访问幻灯片的图像集合,并使用Remove方法与您希望删除的图像的零基索引。 当您知道图片在图片集中的确切位置时,这种方法就能很好地发挥作用。

using IronPPT;

// Load an existing presentation
var document = new PresentationDocument("real_sample.pptx");

// Remove the first image found on the second slide
document.Slides[1].Images[0].Remove();

// Save the updated presentation
document.Save("removed-image.pptx");
C#

图像移除前

从 PowerPoint 幻灯片中按索引删除图像(视图之前)

图像去除后

从 PowerPoint 幻灯片中按索引删除图像(查看后)

删除所有图片

对于需要大量删除一个文档中所有for循环:一次遍历所有文档页面,第二次重新遍历和移除每页标识的所有图像。 下面给出一个例子。

using IronPPT;
using IronPPT.Models;

// Load an existing presentation
var document = new PresentationDocument("real_sample.pptx");

// Remove all images from every slide
for (int s = 0; s < document.Slides.Count; s++)       // Loop through all slides
{
    var slide = document.Slides[s];                   // Get the current slide

    for (int i = slide.Images.Count - 1; i >= 0; i--) // Loop backward through images on this slide
    {
        slide.Images[i].Remove();                     // Remove each image
    }
}

// Save the updated presentation
document.Save("removed-images.pptx");

批量删除之前

批量从 PowerPoint 幻灯片中按索引删除图像(视图之前)

批量删除后

如您所见,幻灯片 2 和 4 中的所有图片都已删除。

批量从 PowerPoint 幻灯片中删除按索引排列的图像(查看后)

常见问题解答

在 PowerPoint 演示文稿中添加图像时,可以使用哪些图像文件格式?

IronPPT 支持常见的图像格式,包括 JPEG、PNG、BMP、GIF 和 TIFF。在将图像添加到演示文稿时,该库可自动处理格式转换和优化,确保与大多数图像源兼容。

如何在演示文稿中的特定幻灯片上添加图片?

要使用 IronPPT 添加图像,首先要使用 Image.Create() 创建一个图像对象,其中包含图像文件路径,然后使用 slide.Images.Add() 将其添加到特定幻灯片中。您可以通过索引访问幻灯片,例如:ppt.Slides[0].Images.Add(image) 将图片添加到第一张幻灯片。

我可以通过编程控制图片的大小和尺寸吗?

是的,IronPPT 允许您使用图像对象的 "宽度 "和 "高度 "属性设置图像尺寸。只需在将图像添加到幻灯片之前或之后,以点为单位为这些属性赋值即可,例如 image.Width = 400 和 image.Height = 300。

如何在幻灯片的特定位置放置图片?

IronPPT 可使用带有 x、y 坐标的 Position 属性对图像进行精确定位。坐标系以左上角(0,0)为起点,数值以点为单位,可将图像放置在幻灯片表面的任何位置。

是否可以替换 PowerPoint 演示文稿中的现有图像?

是的,IronPPT 支持替换演示文稿中的现有图像。您可以识别要替换的图像,并用新的图像对象替代它们,同时保持相同的位置和属性,确保无缝更新您的可视化内容。

能否以编程方式删除幻灯片中的图像?

IronPPT 提供从演示文稿中单独或批量移除图像的功能。您可以通过访问幻灯片的图像集合并使用适当的移除方法来移除特定图像。

Why should I manage images in a PowerPoint presentation programmatically?

Managing images programmatically with IronPPT enhances efficiency, ensures precision in positioning and sizing, and allows for dynamic updates, essential for professional and scalable presentations.

What is the 'Image' class used for in IronPPT?

In IronPPT, the `Image` class is used to create image objects that you can load from files and manipulate by setting different properties before adding them to PowerPoint slides.

Can I export a modified PowerPoint with new images using IronPPT?

Yes, once you've made modifications or additions of images in a PowerPoint, you can export the presentation as a PPTX file using IronPPT, preserving all your adjustments.

What are some common image properties that can be adjusted using IronPPT?

Common image properties include `Height`, `Width`, `Angle`, `Position`, and `FrameShape`, allowing for comprehensive customization of image appearance and placement on slides.

Ahmad Sohail
全栈开发者

Ahmad 是一名全栈开发人员,拥有扎实的 C#、Python 和 Web 技术基础。他对构建可扩展的软件解决方案深感兴趣,并喜欢探索设计和功能在实际应用中如何结合。

...
阅读更多

准备开始了吗?

Nuget Downloads 6,070版本:2026.9刚刚发布

C# 用于 PDF 的 NuGet 库
通过 NuGet 安装

版本: 2026.9

PM > Install-Package IronPPT
nuget.org/packages/IronPPT/
  1. 在解决方案资源管理器中,右键点击引用,管理 NuGet 包
  2. 选择浏览并搜索"IronPPT"
  3. 选择包并安装
C# PDF DLL
下载 DLL

版本: 2026.9

  1. 下载并解压IronPPT到你的解决方案目录中的~/Libs等位置
  2. 在Visual Studio解决方案资源管理器中,右键单击引用。选择浏览,"IronPPT.dll"

许可证从$999

Key in blue circle

立即获取免费的 30 天试用版密钥

Your trial license will be sent to your email address

无任何限制。100% 解锁。无需信用卡。

bullet_checked无需信用卡或创建账户无任何限制。100% 解锁。无需信用卡。
  • Logo Aetna
  • Logo NASA
  • Logo GE
  • Logo Porsche
  • Logo USDA
  • Logo Qatar
Join Millions of Engineers who’ve tried IronPDF
预约您的免费现场演示
Booking Badge

深受全球数百万工程师信赖

Iron Software 的客户徽标
获取您的无义务咨询
填写下面的表格或通过sales@ironsoftware.com
您的资料将始终保密。
深受全球数百万工程师信赖
Iron Software 的客户徽标
立即获取您的免费30 天试用密钥
无需信用卡或创建账户