翻譯|使用教程|編輯:胡濤|2022-10-31 15:14:49.130|閱讀 170 次
概述:本教程將向您展示如何使用 Spire.Doc 制作圖像的顏色,歡迎查閱~
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
Spire.Doc for .NET是一款專門對 Word 文檔進行操作的 .NET 類庫。在于幫助開發人員無需安裝 Microsoft Word情況下,輕松快捷高效地創建、編輯、轉換和打印 Microsoft Word 文檔。擁有近10年專業開發經驗Spire系列辦公文檔開發工具,專注于創建、編輯、轉換和打印Word/PDF/Excel等格式文件處理,小巧便捷。
本教程將向您展示如何使用 Spire.Doc 制作圖像的顏色。
下面的屏幕截圖顯示了一個帶有黑白顏色的示例圖像:
詳細步驟:
第 1 步:實例化一個 Document 對象并加載 Word 文件。
Document doc = new Document(); doc.LoadFromFile("Input.docx");
第 2 步:獲取第一部分中的第一個段落。
Paragraph paragraph = doc.Sections[0].Paragraphs[0];
第 3 步:將段落中圖像的黑色設置為透明。
foreach (DocumentObject obj in paragraph.ChildObjects) { if (obj is DocPicture) { (obj as DocPicture).TransparentColor = Color.Black; } }
第 4 步:保存文件。
doc.SaveToFile("Result.docx", FileFormat.Docx2013);
截圖:
完整代碼:
using Spire.Doc; using Spire.Doc.Documents; using Spire.Doc.Fields; using System.Drawing; namespace Transeperant { class Program { static void Main(string[] args) { //Instantiate a Document object Document doc = new Document(); //Load the Word file doc.LoadFromFile("Input.docx"); //Get the first paragraph in the first section Paragraph paragraph = doc.Sections[0].Paragraphs[0]; //Set the black color of the image(s) in the paragraph to transperant foreach (DocumentObject obj in paragraph.ChildObjects) { if (obj is DocPicture) { (obj as DocPicture).TransparentColor = Color.Black; } } //Save the file doc.SaveToFile("Result.docx", FileFormat.Docx2013); } } }
以上便是 何在 C# 中為 Word 中的圖像設置 Transeperant 顏色,如果您有其他問題也可以繼續瀏覽本系列文章,獲取相關教程,你還可以給我留言或者加入我們的官方技術交流群。
歡迎下載|體驗更多E-iceblue產品
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn