public static class Extensions
{
/// <summary>
/// Converts a Microsoft.Office.Interop.Word.WdColor object to a
/// System.Drawing.Color object.
/// If Word's color only contains RGB values without an alpha value,
/// the alpha value will be set to 255.
/// </summary>
public static Color ToColor(this WdColor originalColor)
{
// Cast to numeric value so we can isolate RGBA elements
int wordColor = (int)originalColor;
// Isolate alpha element. Shift right to set its range to [0-255].
int alphaTemp = (int)((wordColor & 0xFF000000) >> 24);
// Check that it's not completely transparent. If so, make it visible.
int alpha = (alphaTemp == 0) ? 255 : alphaTemp;
// Isolate R,G,B elements.
int r = (wordColor & 0x000000FF);
int g = ((wordColor & 0x0000FF00) >> 8);
int b = ((wordColor & 0x00FF0000) >> 16);
return Color.FromArgb(alpha, r, g, b);
}
}