以编程方式使飞镖中的十六进制颜色变亮或变暗 [英] Programmatically Lighten or Darken a hex color in dart
本文介绍了以编程方式使飞镖中的十六进制颜色变亮或变暗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将此哈希颜色代码#159424 (绿色(GREEN-COLOR))转换为以编程方式进一步加深和加亮。
I am trying to convert this hash color code #159424 (GREEN-COLOR) to more darken and lighten programmatically. How to do this please help?
使绿色变深
toDarkColor(String hashColor){
// how to convert that hash string to make green color darker?
}
使绿色变浅
toLightColor(String hashColor){
// how to convert that hash string to make green color lighter?
}
推荐答案
您可以使用 tinycolor 包:
TinyColor.fromString("#159424").darken(10).color
编辑:
您可以将颜色
转换回十六进制字符串,如下所示:
You can convert Color
back to hex string like this:
String toHex(Color color) {
return "#${color.red.toRadixString(16).padLeft(2, "0")}"
"${color.green.toRadixString(16).padLeft(2, "0")}"
"${color.blue.toRadixString(16).padLeft(2, "0")}";
}
或者如果您想要不透明/ alpha:
or if you want opacity/alpha:
String toHex(Color color) {
return "#${color.alpha.toRadixString(16).padLeft(2, "0")}"
"${color.red.toRadixString(16).padLeft(2, "0")}"
"${color.green.toRadixString(16).padLeft(2, "0")}"
"${color.blue.toRadixString(16).padLeft(2, "0")}";
}
这篇关于以编程方式使飞镖中的十六进制颜色变亮或变暗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文