IronPPT 操作指南 管理圖像 如何在 PowerPoint 中管理圖像 Ahmad Sohail 更新:2026年1月10日 下載 IronPPT NuGet 下載 開始免費試用 法學碩士副本 法學碩士副本 將頁面複製為 Markdown 格式,用於 LLMs 在 ChatGPT 中打開 請向 ChatGPT 諮詢此頁面 在雙子座打開 請向 Gemini 詢問此頁面 在 Grok 中打開 向 Grok 詢問此頁面 打開困惑 向 Perplexity 詢問有關此頁面的信息 分享 在 Facebook 上分享 分享到 X(Twitter) 在 LinkedIn 上分享 複製連結 電子郵件文章 This article was translated from English: Does it need improvement? Translated View the article in English 多媒體元素構成了 PowerPoint 簡報不可或缺的結構。 圖片尤其能夠提供視覺背景,並強化每張投影片上呈現的訊息。有效的圖片管理(無論是插入新圖片、更新現有圖片還是清理過時的圖片)對於保持簡報的專業性和可擴展性至關重要。 本指南示範如何使用 IronPPT 以程式處理影像。 ## 如何在 PowerPoint 中管理圖像 下載用於 PowerPoint 自動化的 C# 庫 載入或建立 PowerPoint 簡報 使用Image類別處理影像對象 執行操作:插入、修改、取代或刪除影像 儲存並匯出為 PPTX 格式 新增圖片 若要使用 IronPPT 在 PowerPoint 文件中新增圖像,請建立新的文件物件(或從現有文件載入)。 然後,使用Image類別建立一個引用檔案的圖像物件。影像載入完成後,將其新增至文件中,並指定其顯示的幻燈片編號。 從那裡,可以使用Height 、 Width和Angle等屬性來更改圖像屬性。 最後,匯出包含新新增影像的文件。 :path=/static-assets/ppt/content-code-examples/how-to/manage-image-add-image-add-image.cs 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"); Imports IronPPT Imports IronPPT.Models ' Create a new presentation document Dim document As New PresentationDocument() ' Create and load an image from file Dim image As New Image() image.LoadFromFile("image.jpg") ' Add image to the first slide (index 0) Dim 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") $vbLabelText $csharpLabel 圖像屬性 請查看下表中的圖像屬性選項。 屬性 描述 例子 高度 設定圖像高度(以磅為單位)。 image.Height=300;。 寬度 設定影像寬度(以磅為單位)。 image.Width=400;。 Angle 將影像旋轉指定的角度(以度為單位)。 image.Angle=45;。 職位 使用 x 和 y 座標設定影像在投影片上的位置。 image.Position = (200, 200); 框架形狀 使用 ShapeType 枚舉值設定影像的框架形狀。 image.FrameShape=IronPPT.Enums.ShapeType.RoundRectangle;。 修改已新增的圖像屬性 將圖片新增至投影片後,您可以修改其屬性以調整外觀和位置。 例如,使用Height 、 Width和Angle等屬性來自訂圖像尺寸和旋轉。 調整這些設定可以讓你微調影像在簡報中的顯示方式。 :path=/static-assets/ppt/content-code-examples/how-to/manage-image-add-image-modify-properties.cs 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"); Imports IronPPT Imports IronPPT.Models Imports IronPPT.Enums ' Load an existing presentation document Dim document As New PresentationDocument("existing-presentation.pptx") ' Create and load an image from file Dim image As New Image() image.LoadFromFile("image.jpg") ' Add image to the second slide (index 1) Dim 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") $vbLabelText $csharpLabel 替換影像 使用 IronPPT 取代圖片是一項直覺的操作。 首先,將簡報文件和新圖像載入到一個新的Image物件中。 然後,透過選擇要更新的圖像的幻燈片和索引來定位該圖像,例如Slides[0].Images[0] (對於第一張幻燈片上的第一張圖像)。 完成後,使用新的圖像物件呼叫Replace方法並匯出檔案。 :path=/static-assets/ppt/content-code-examples/how-to/manage-image-replace-image-replace-image.cs 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"); Imports IronPPT Imports IronPPT.Models ' Load an existing presentation Dim document As New PresentationDocument("sample.pptx") ' Load the replacement image Dim replaceImage As 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") $vbLabelText $csharpLabel 原來的 結果 按索引刪除影像 刪除圖像最簡單的方法是按其索引位置刪除。 存取幻燈片的圖像集合,並使用Remove方法和要刪除的圖像的從零開始的索引。 當您知道影像在影像集中的確切位置時,這種方法非常有效。 :path=/static-assets/ppt/content-code-examples/how-to/manage-image-remove-image-remove-by-index.cs using IronPPT; // Create a new presentation var document = new PresentationDocument("real_sample.pptx"); // Remove the first image found in the first slide document.Slides[1].Images[0].Remove(); // Save the updated presentation document.Save("removed-image.pptx"); Imports IronPPT ' Create a new presentation Dim document As New PresentationDocument("real_sample.pptx") ' Remove the first image found in the first slide document.Slides(1).Images(0).Remove() ' Save the updated presentation document.Save("removed-image.pptx") $vbLabelText $csharpLabel 移除影像前 移除影像後 刪除所有圖片 對於需要大量刪除文件中所有 圖片 檔案的情況,我們可以使用兩個 for 環路:一次遍歷所有文件頁面,兩次重申並刪除每頁中所有已識別的圖片。 下面給出一個例子。 :path=/static-assets/ppt/content-code-examples/how-to/manage-image-remove-all-images.cs 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"); Imports IronPPT Imports IronPPT.Models ' Load an existing presentation Dim document As New PresentationDocument("real_sample.pptx") ' Remove all images from every slide For s As Integer = 0 To document.Slides.Count - 1 ' Loop through all slides Dim slide = document.Slides(s) ' Get the current slide For i As Integer = slide.Images.Count - 1 To 0 Step -1 ' Loop backward through images on this slide slide.Images(i).Remove() ' Remove each image Next Next ' Save the updated presentation document.Save("removed-images.pptx") $vbLabelText $csharpLabel 批量刪除之前 批量刪除後 如您所見,第 2 張和第 4 張投影片中的所有影像都已刪除。 常見問題解答 在 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 可使用具有 x,y 座標的 Position 屬性來進行精確的影像定位。坐標系統從左上角 (0,0) 開始,數值以點為單位,讓您可以將影像放置在幻燈片表面的任何位置。 是否可以取代 PowerPoint 簡報中的現有圖片? 是的,IronPPT 支援取代簡報中的現有圖片。您可以識別要取代的圖像,並以新的圖像物件取代,同時維持相同的位置和屬性,確保視覺內容的無縫更新。 我可以用程式移除幻燈片上的圖片嗎? IronPPT 提供從簡報中個別或大量移除圖片的功能。您可以透過存取幻燈片的圖片集合,並使用適當的移除方法來移除特定的圖片。 Ahmad Sohail 立即與工程團隊聊天 全堆疊開發人員 Ahmad 是一名全堆疊開發人員,在 C#、Python 和 Web 技術方面有深厚的基礎。 在加入 Iron Software 團隊之前,Ahmad 從事自動化專案和 API 整合工作,專注於改善效能和開發人員體驗。在空閒時間,他喜歡嘗試 UI/UX 想法,為開源工具貢獻心力,偶爾也會鑽研技術撰寫和文件,讓複雜的主題更容易理解。 準備好開始了嗎? Nuget 下載 4,038 | 版本: 2026.2 剛剛發布 免費 NuGet 下載 總下載量:4,038 查看許可證