Question

I have a list of color values encoded as signed integers (OLE I think) in a legacy INI file that I need to translate into (A)RGB values with .NET. An INI example:

[INI_Section]
Color=-2147483633

Doing something like:

Color.FromArgb(-2147483633)

gives an alpha-blended version of a color that is not at all what I expect. I think that a value like -2147483633 is supposed to represent a system-defined, or named color like ButtonFace. Is there a .NET method for translating these legacy colors properly? Note that pInvoke to OlePro32.dll is not an option.

Was it helpful?

Solution

You can use ColorTranslator.FromOle to do the conversion.
http://msdn.microsoft.com/en-us/library/system.drawing.colortranslator.fromole.aspx

OTHER TIPS

If from some reason you cannot use System.Drawing lib (e.g. in Azure function) than you can calculate like this:

                var ole = 6579300;
                var red = ole % 256;
                var green = (ole / 256) % 256;
                var blue = (ole / 65536) % 256;
                var backToOle = red + (green * 256) + (blue * 256 * 256);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top