gpt4 book ai didi

c# - 将 excel Color BGR 转换为 RGB

转载 作者:行者123 更新时间:2023-11-30 22:05:01 24 4
gpt4 key购买 nike

我找到了一个 articleInterior.Color 返回的值在 BGR 中,我试图将它转换为 RGB,但我仍然得到奇怪的颜色

我正在尝试使用 ControlPaint.Light 在 excel 单元格中检索基色以照亮它:

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);
}

我做错了什么?

最佳答案

这个method返回颜色

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;
}

关于c# - 将 excel Color BGR 转换为 RGB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24672889/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com