This tutorial is going to show you how to make a color of a image transparent using Spire.Doc.
Below screenshot shows an example image with black and white colors:
Detail steps:
Step 1: Instantiate a Document object and Load the Word file.
Document doc = new Document(); doc.LoadFromFile("Input.docx");
Step 2: Get the first Paragraph in the first section.
Paragraph paragraph = doc.Sections[0].Paragraphs[0];
Step 3: 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; } }
Step 4: Save the file.
doc.SaveToFile("Result.docx", FileFormat.Docx2013);
Screenshot:
Full code:
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); } } }