跳到主要内容

GetRGB

获取颜色的 RGB 分量。

语法

expression.GetRGB();

expression - 表示 ApiColor 类的变量。

参数

此方法没有任何参数。

返回值

Object

示例

提取文档中颜色的红、绿、蓝通道值。

// How do I read the individual RGB components of a color in a document?

// Compare channel values across theme, auto, and hex colors to understand how each type resolves in a document.

const doc = Api.GetDocument();

const themeColor = Api.ThemeColor('accent1');
const autoColor = Api.AutoColor();
const hexColor = Api.HexColor('#FF0000');

const themeColorRGB = themeColor.GetRGB();
const autoColorRGB = autoColor.GetRGB();
const hexColorRGB = hexColor.GetRGB();

const paragraph = doc.GetElement(0);
paragraph.AddText('RGB of themeColor: ' + themeColorRGB.r + ', ' + themeColorRGB.g + ', ' + themeColorRGB.b);
paragraph.AddLineBreak();
paragraph.AddText('RGB of autoColor: ' + autoColorRGB.r + ', ' + autoColorRGB.g + ', ' + autoColorRGB.b);
paragraph.AddLineBreak();
paragraph.AddText('RGB of hexColor: ' + hexColorRGB.r + ', ' + hexColorRGB.g + ', ' + hexColorRGB.b);
paragraph.AddLineBreak();
paragraph.AddText('RGB for theme colors and auto color are always opaque black; actual color depends on the document theme.');