【问题标题】:How do I convert a hexidecimal color (with alpha) to an int in Jython?如何在 Jython 中将十六进制颜色(带 alpha)转换为 int?
【发布时间】:2011-04-16 07:44:13
【问题描述】:
我需要将 ARGB 十六进制转换为 Jython 中的 int 以获得颜色。我试过使用 longs、hex() 和其他东西的组合,但似乎无法让它工作。
当我尝试将 0x80ff3333 转换为 int 时,出现此错误“TypeError : 5th arg can't be coerced to int”。
我猜十六进制中有太多字节无法转换它。有人知道这种转换的语法吗?
谢谢!
【问题讨论】:
标签:
colors
hex
jython
int
alpha
【解决方案1】:
只需将基数的第二个参数传递给 int 函数。
Jython 2.5.2b1 (trunk:7081M, Jul 20 2010, 18:56:05)
[Java HotSpot(TM) 64-Bit Server VM (Apple Inc.)] on java1.6.0_20
Type "help", "copyright", "credits" or "license" for more information.
>>> int('0x80ff3333',16)
2164208435L
>>> # verification
>>> hex(_)
'0x80ff3333L'