//
// 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
{
// Set transparent color picture in picture.
public class PicEffTransparentColor
{
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);
// Set black to transparent:
var picture = doc.Body.AddParagraph().AddRun().AddPicture(bytes, @"image/jpeg", 450, 300);
picture.ImageData.SetColorTransparent(new UserColor(Color.Black));
// To show that parts of the picture are now transparent, fill the background with confetti:
picture.Fill.Type = FillType.Pattern;
picture.Fill.PatternFill.Type = PatternFillType.LargeConfetti;
picture.Fill.PatternFill.BackColor.RGB = Color.LightYellow;
picture.Fill.PatternFill.ForeColor.RGB = Color.Red;
doc.Body.AddParagraph($"Black is transparent, with confetti fill", captionStyle);
// Done:
return doc;
}
}
}