Delphi 德尔菲法10.2主题-“;“轻”;vsd“;“黑暗”;

Delphi 德尔菲法10.2主题-“;“轻”;vsd“;“黑暗”;,delphi,themes,Delphi,Themes,使用Delphi 10.2和主题:是否有可靠的方法确定当前主题是“浅”(白色或浅clWindow颜色)还是“深”(黑色、接近黑色或深clWindow颜色)主题?我必须用特定的颜色绘制某些元素(例如,报警指示灯为红色,无论主题颜色如何),但需要在深色背景下使用“亮”红色,而在浅色背景下使用更“柔和”的红色 我试过查看主题的clWindow颜色的不同RGB组件集(即,若3个组件颜色中的2个>7F,则为“灯光”主题),但对于某些主题而言,这并不总是可靠的 是否有更好/更可靠的方法来确定这一点?如果您正

使用Delphi 10.2和主题:是否有可靠的方法确定当前主题是“浅”(白色或浅clWindow颜色)还是“深”(黑色、接近黑色或深clWindow颜色)主题?我必须用特定的颜色绘制某些元素(例如,报警指示灯为红色,无论主题颜色如何),但需要在深色背景下使用“亮”红色,而在浅色背景下使用更“柔和”的红色

我试过查看主题的clWindow颜色的不同RGB组件集(即,若3个组件颜色中的2个>7F,则为“灯光”主题),但对于某些主题而言,这并不总是可靠的


是否有更好/更可靠的方法来确定这一点?

如果您正在编写IDE插件,您可以询问
物联网辅助主题服务的
Borlandedesvices
。后者包含一个属性
ActiveTheme
,它为您提供了当前主题名称。

根据Tom的信息,我实现了以下功能,该功能适用于我尝试过的每个主题:

function IsLightTheme: Boolean;
var
  WC: TColor;
  PL: Integer;
  R,G,B: Byte;
begin
  //if styles are disabled, use the default Windows window color,
  //otherwise use the theme's window color
  if (not StyleServices.Enabled) then
    WC := clWindow
  else
    WC := StyleServices.GetStyleColor(scWindow);

  //break out it's component RGB parts
  ColorToRGBParts(WC, R, G, B);

  //calc the "perceived luminance" of the color.  The human eye perceives green the most,
  //then red, and blue the least; to determine the luminance, you can multiply each color
  //by a specific constant and total the results, or use the simple formula below for a
  //faster close approximation that meets our needs. PL will always be between 0 and 255.
  //Thanks to Glenn Slayden for the formula and Tom Brunberg for pointing me to it!
  PL := (R+R+R+B+G+G+G+G) shr 3;

  //if the PL is greater than the color midpoint, it's "light", otherwise it's "dark".
  Result := (PL > $7F);
end;```

你说的是IDE插件吗?你需要考虑背景中每个颜色组件的亮度。可以找到公式。然后你可以用$7F.Uwe-No进行简单的比较。不幸的是,主题名称并不能满足我的需要。我认为汤姆的答案是正确的。汤姆——至少在我测试过的主题中,这似乎是正确的。谢谢