将excel颜色BGR转换为RGB

我发现一篇文章说,由Interior.Color返回的值是在BGR,我试图将其转换为RGB,但我仍然有奇怪的颜色

而我试图在Excel单元格中检索基本颜色来使用ControlPaint.Light来点亮它,如下所示:

 int rgbColor = ExcelDoc.BGRToRGB((int)contentCanonical.Interior.Color); Color canonicalColor = ColorTranslator.FromOle(rgbColor); Color backgroundColor = ControlPaint.Light(canonicalColor, 75); 

这里是我的转换方法

 public static int BGRToRGB(int bgr) { byte[] hexBGR; byte[] hexRGB = new byte[4] {0,0,0,0}; hexBGR = BitConverter.GetBytes(bgr); hexRGB[0] = hexBGR[0]; hexRGB[1] = hexBGR[3]; hexRGB[2] = hexBGR[2]; hexRGB[3] = hexBGR[1]; return BitConverter.ToInt32(hexRGB, 0); } 

我究竟做错了什么?

这个方法返回颜色

 public static Color From0BGR(int bgrColor) { // Get the color bytes var bytes = BitConverter.GetBytes(bgrColor); // Return the color from the byte array return Color.FromArgb(bytes[0], bytes[1], bytes[2]); } 

这将从rgb颜色返回bgr颜色int

 public static int Get0BGR(Color rgbColor) { // Return a zero-alpha 24-bit BGR color integer return (0 << 24) + (rgbColor.B << 16) + (rgbColor.G << 8) + rgbColor.R; } 

我正在使用这个function(我正在“剪切”颜色的阿尔法部分)

  /// <summary> /// Converts the color to an Argb color /// </summary> /// <param name="color">Color to convert</param> /// <returns>The Argb color</returns> public static int ToArgb(int color) { int Argb = (color >> 16) | (color & 0xFF) << 16 | (color & 0x00FF00); return Argb; } /// <summary> /// Converts the color to a MSO Color /// </summary> /// <param name="Argb">Color to convert</param> /// <returns>The MSO color</returns> public static int ToMsoColor(int Argb) { Argb &= 0xFFFFFF; int color = (Argb >> 16) | (Argb & 0xFF) << 16 | (Argb & 0x00FF00); return color; }