Word控件Spire.Doc 【图像形状】教程(11): 如何在 C# 中为 Word 中的图像设置 Transeperant 颜色

本教程将向您展示如何使用 Spire.Doc 制作图像的颜色,欢迎查阅~

本教程将向您展示如何使用 Spire.Doc 制作图像的颜色。

下面的屏幕截图显示了一个带有黑白颜色的示例图像:

在 C# 中为 Word 中的图像设置 Transeperant 颜色

详细步骤:

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

截图

在 C# 中为 Word 中的图像设置 Transeperant 颜色

完整代码

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 objectDocument doc = new Document();//Load the Word filedoc.LoadFromFile("Input.docx");//Get the first paragraph in the first sectionParagraph paragraph = doc.Sections[0].Paragraphs[0];//Set the black color of the image(s) in the paragraph to transperantforeach (DocumentObject obj in paragraph.ChildObjects){if (obj is DocPicture){(obj as DocPicture).TransparentColor = Color.Black;}}//Save the filedoc.SaveToFile("Result.docx", FileFormat.Docx2013);}}}

以上便是 何在 C# 中为 Word 中的图像设置 Transeperant 颜色,如果您有其他问题也可以继续浏览本系列文章,获取相关教程,你还可以给我留言或者加入我们的官方技术交流群。


欢迎下载|体验更多E-iceblue产品

获取更多信息请咨询在线客服  


标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2022年9月27日
下一篇 2022年9月27日

相关推荐

发表回复

登录后才能评论