How do you decode a hex color with an alpha component?

getrgb parses supported color strings and can return four components for a color with alpha.

Pixel experiment and interpretation

A toolbar sends #FF000080. Its last pair encodes an opacity byte in hexadecimal; it does not mean eighty percent.

from PIL import ImageColor

ImageColor.getrgb('#FF000080')

Result (255, 0, 0, 128)

中文

怎样把带十六进制 alpha 的颜色转成通道值?

getrgb 解析支持的颜色字符串,带 alpha 的形式可返回四个分量。

像素实验与适用边界

工具栏传来 #FF000080,末尾的 80 是十六进制透明度字节。不要把它当作十进制的百分之八十。

from PIL import ImageColor

ImageColor.getrgb('#FF000080')

结果 (255, 0, 0, 128)

References / 参考来源

Keep reading / 继续阅读