//
// This code is part of Document Solutions for Word demos.
// Copyright (c) MESCIUS inc. All rights reserved.
//
using System;
using System.IO;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using GrapeCity.Documents.Word;
namespace DsWordWeb.Demos
{
// Change color in picture.
public class PicEffChangeColor
{
public GcWordDocument CreateDocx()
{
var doc = new GcWordDocument();
Util.SetNarrowMargins(doc);
var captionStyle = doc.Styles.Add("CaptionStyle", doc.Styles[BuiltInStyleId.BodyTextFirstIndent2]);
// Read image from a file:
var bytes = File.ReadAllBytes(Path.Combine("Resources", "Images", "wargravepink.jpg"));
// Original picture:
doc.Body.AddParagraph().AddRun().AddPicture(bytes, @"image/jpeg", 450, 300);
doc.Body.AddParagraph("Original picture", captionStyle);
// Add color change:
var picture = doc.Body.AddParagraph().AddRun().AddPicture(bytes, @"image/jpeg", 450, 300);
var colorChange = picture.ImageData.Effects.AddColorChange(new UserColor(Color.Black), new UserColor(Color.CadetBlue));
doc.Body.AddParagraph($"Color changed from {colorChange.ColorFrom.RGB} to {colorChange.ColorTo.RGB}", captionStyle);
// Done:
return doc;
}
}
}