Scintillia 标记背景的颜色与预期不同

发布于 2024-12-21 08:12:38 字数 1031 浏览 4 评论 0原文

我正在尝试为我正在编写的记事本++插件设置Markerbackgrounds,以便可以突出显示某些行。颜色存储为从 Color.ToArgb() 转换而来的整数:

int colour = Convert.ToInt32(Color.LightSkyBlue.ToArgb())

根据我对 Scintillia 文档的理解,它只接受 RGB 颜色,因此我使用以下函数去除颜色的 Alpha 部分。这确实设置了一种颜色,但我得到的是橙色而不是蓝色,而不是蓝色。这是设置标记背景颜色的正确方法吗?

       private static void DefineColor(int type, int colour)
    {
        string hexValue = colour.ToString("X");
        hexValue = hexValue.Remove(0, 2);

        //hexValue = "0x" + hexValue

        int decValue = Convert.ToInt32(ColorTranslator.FromHtml(hexValue));
        //int decValue = int.Parse("FF", System.Globalization.NumberStyles.AllowHexSpecifier);

        Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERDEFINE, type, (int)SciMsg.SC_MARK_BACKGROUND);
        Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERSETBACK, type, decValue);
        Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERSETFORE, type, 0);
    }

I'm trying to set Markerbackgrounds for a notepad++ plugin I'm writting so certain lines can be highlighted. The colours are stored as ints which are converted from Color.ToArgb():

int colour = Convert.ToInt32(Color.LightSkyBlue.ToArgb())

From what I understand of the Scintillia documentation it only accepts RGB colours so I use the following function to strip out the Alpha part of the colour. This does set a colour but instead of blue I'm getting orange instead of blue. Is this the right way to set a marker background colour?

       private static void DefineColor(int type, int colour)
    {
        string hexValue = colour.ToString("X");
        hexValue = hexValue.Remove(0, 2);

        //hexValue = "0x" + hexValue

        int decValue = Convert.ToInt32(ColorTranslator.FromHtml(hexValue));
        //int decValue = int.Parse("FF", System.Globalization.NumberStyles.AllowHexSpecifier);

        Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERDEFINE, type, (int)SciMsg.SC_MARK_BACKGROUND);
        Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERSETBACK, type, decValue);
        Win32.SendMessage(PluginBase.nppData._scintillaMainHandle, SciMsg.SCI_MARKERSETFORE, type, 0);
    }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

很酷不放纵 2024-12-28 08:12:38

这会去掉任何 alpha 值:

var colorOnly = Color.FromArgb(c.R, c.G, c.B);

这会将颜色转换为整数值:

int i = c.ToArgb();

两者一起:

int i = Color.FromArgb(c.R, c.G, c.B).ToArgb();

但我不知道 Scintillia 是否使用相同的颜色表示。可以将值存储为 BGR 而不是 RGB 格式。

int bgr = (c.B * 256 + c.G) * 256 + c.R;

This strips off any alpha value:

var colorOnly = Color.FromArgb(c.R, c.G, c.B);

This converts the color to a integer value:

int i = c.ToArgb();

Both together:

int i = Color.FromArgb(c.R, c.G, c.B).ToArgb();

But I don't know, if Scintillia uses the same color representation. May it stores the value in BGR instead of RGB format.

int bgr = (c.B * 256 + c.G) * 256 + c.R;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文