colors - StageXL 和颜色值

标签 colors dart stagexl

我试图设置一个任意颜色选择器来获取要传递给 Graphics.fillColor() 的值。
该方法的签名是“动态填充颜色(int color)”,因此颜色似乎不是 RGB/RGBA,而是某个整数。 Color 类为这些值定义了一堆常量,但我希望能够使用用户在我的颜色选择器中选择的任何颜色。

我尝试使用以下过程从 RGB 转换为 Hex:

String r_hex_str   = p_rbg_color_lst[0].toRadixString(16); //to hexadecimal
String g_hex_str   = p_rbg_color_lst[1].toRadixString(16);
String b_hex_str   = p_rbg_color_lst[2].toRadixString(16);
String rgb_hex_str = '0x$r_hex_str$g_hex_str$b_hex_str';

int color_rgb_int = int.parse(rgb_hex_str);

return color_rgb_int;

但是 fillColor() 方法对新的颜色参数没有反应。
为了说明,上述过程将 [100, 145, 185] 作为颜色 RGB 三元组,并输出 6590905 作为整数输出。

StageXL.Color.Red 常量为 4294901760

6590905 和 4294901760 的长度甚至不同,这告诉我我使用的算法是错误的......

有任何想法吗?
谢谢

最佳答案

它似乎使用了额外的两个字节来存储 alpha 值。因此,您需要修改代码以添加:

String a_hex_str   = 255.toRadixString(16); // 255 is ff, or fully opaque
String r_hex_str   = p_rbg_color_lst[0].toRadixString(16); 
String g_hex_str   = p_rbg_color_lst[1].toRadixString(16);
String b_hex_str   = p_rbg_color_lst[2].toRadixString(16);
String rgb_hex_str = '0x$a_hex_str$r_hex_str$g_hex_str$b_hex_str';

int color_rgb_int = int.parse(rgb_hex_str);

return color_rgb_int;

输入 [100, 145, 185] 为 4284780985

关于colors - StageXL 和颜色值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22275294/

相关文章:

excel - 如何使图表填充引用单元格颜色和图案?

html - SSI 菜单链接需要颜色更改 : CSS or HTML?

dart - 谁能告诉我如何使用 flutter 打开另一个应用程序?

dart - 我如何在我的应用程序中使用静态成员,这取决于我的库的依赖性

dart - 没有用于graphics.strokeColor的可选宽度参数?

dart - StageXL GraphicsGradient

python - 交换原始文件的颜色 channel (BGGR -> RGGB)

python - 为什么 seaborn countplots 和 histplots 显示相同的十六进制颜色不同?

firebase - 没有为类 'instance' 定义 setter/getter 'FirebaseUser'

dart - 从 HttpClientResponse 检索响应正文