Reputation: 441
i try to get the current Color of a layer in an visio document as RGB. My problem are colors, that are not set with "RGB(1,2,3)" in the formula. There are some colors set, based on the current scheme. So there are colors with "255" (layer color not chosen) or "19" (the used color depends on the active scheme, eg. dark-gray).
I need a way to transform "19" to an RGB-scheme, depending on the current scheme and variant.
Heiko
Upvotes: 0
Views: 478
Reputation: 12245
Visio has first 24 colors fixed. All others come in form of RGB(R, G, B)
formula. The list of fixed colors can be obtained form Document.Colors
. All in all, you could start with following:
using System.Drawing;
using System.Text.RegularExpressions;
using Visio = Microsoft.Office.Interop.Visio;
static Color GetLayerColor(Visio.Layer layer)
{
var str = layer
.CellsC[(short)Visio.VisCellIndices.visLayerColor]
.ResultStrU[""];
// case 1: fixed color
int colorNum;
if (int.TryParse(str, out colorNum))
{
var visioColor = layer.Document.Colors[colorNum];
return Color.FromArgb(
visioColor.Red,
visioColor.Green,
visioColor.Blue);
}
// case 2: RGB formula
var m = Regex.Match(str, @"RGB\((\d+),\s*(\d+),\s*(\d+)\)").Groups;
return Color.FromArgb(
int.Parse(m[1].Value),
int.Parse(m[2].Value),
int.Parse(m[3].Value)
);
}
Upvotes: 2