IRONSOFTWAREHOME

如何管理PowerPoint中的圖片

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

多媒體元素是PowerPoint簡報的核心結構。 圖片,尤其如此,提供了視覺上下文並強化每個幻燈片上的資訊展示。有效的圖片管理(無論是插入新圖片、更新現有圖片或清理過時圖形)對於維持專業且可拓展的簡報至關重要。

本指南展示了如何使用IronPPT以程式化的方式處理圖片。


新增圖片

要在PowerPoint文件中使用IronPPT新增圖片,請建立一個新的文件物件(或者從現有文件載入)。 然後,從參考文件的Image類建立一個圖片物件。圖片載入後,將其新增到文件中,並指定其應出現的幻燈片號。 從這裡,可以使用WidthAngle等屬性來改變圖片屬性。 最後,匯出包含新增加圖片的文件。

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幻燈片

圖片屬性

在下表中探索圖片屬性選項。

屬性描述例子
Height設定圖片的高度(以點為單位)。image.Height = 300;
Width設定圖片的寬度(以點為單位)。image.Width = 400;
Angle按照指定的角度(以度為單位)旋轉圖片。image.Angle = 45;
Position使用x和y座標設定圖片在幻燈片上的位置。image.Position = (200, 200);
FrameShape使用ShapeType列舉值設定圖片的框架形狀。image.FrameShape = IronPPT.Enums.ShapeType.RoundRectangle;

修改已新增圖片屬性

在幻燈片中新增圖片後,您可以通過修改其屬性來調整外觀和位置。 例如,使用WidthAngle等屬性來自定義圖片的尺寸和旋轉。 調整這些設定能讓您微調圖片在簡報中的外觀。

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中修改圖片屬性

替換圖片

使用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和Height屬性設定圖片尺寸。只需在新增圖片到幻燈片之前或之後,以點數給這些屬性賦值,例如image.Width = 400和image.Height = 300。

如何在幻燈片上的特定位置定位圖片?

IronPPT允許通過Position屬性使用x,y座標精確定位圖片。座標系統從左上角(0,0)開始,單位以點數計算,讓您可以將圖片放置在幻燈片表面的任何位置。

是否可以在PowerPoint簡報中替換現有圖片?

可以,IronPPT支援在簡報中替換現有圖片。您可以識別要替換的圖片並使用新的圖片物件替代,同時保持相同的位置和屬性,確保您的視覺內容無縫更新。

我能否以程式方式從幻燈片中移除圖片?

IronPPT提供功能來從您的簡報中單獨或批量移除圖片。您可以通過存取幻燈片的Images集合並使用適當的移除方法來移除特定圖片。

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和網頁技術堅實基礎的全端開發人員。他對構建可擴展的軟體解決方案深感興趣,並喜歡探索設計和功能在現實世界應用中的結合。

...
閱讀更多

準備好開始了嗎?

Nuget Downloads 6,070版本:2026.9剛剛發布

C# 用於 PDF 的 NuGet 程式庫
using 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天試用金鑰
無需信用卡或帳戶建立