需要解决方案或描述:如何将颜色值从 ARGB 转换为可用于 css 的 RGBA:
例子:
ARGB color : #ff502797 convert to RGBA
RGBA result example: rgba(80,39,151,1)
谢谢。
ARGB包含 4 组 HEX 值(通道):Alpha、Red、Green、Blue。
方案: 示例:#ff502797 - ARGB 格式的颜色 位置上的元素:
0,1 - Alpa (ff)
2,3 - Red (50)
4,5 - Green (27)
6,7 - Blue (97)
在此之后将每个通道转换为十进制。并将他们的位置推入RBGA: rgba(Red,Green,Blue,Alpha) - rgba(80,39,151,1)
示例函数:
function argb2rgba($color)
{
$output = 'rgba(0,0,0,1)';
if (empty($color))
return $output;
if ($color[0] == '#') {
$color = substr($color, 1);
}
if (strlen($color) == 8) { //ARGB
$opacity = round(hexdec($color[0].$color[1]) / 255, 2);
$hex = array($color[2].$color[3], $color[4].$color[5], $color[6].$color[7]);
$rgb = array_map('hexdec', $hex);
$output = 'rgba(' . implode(",", $rgb) . ',' . $opacity . ')';
}
return $output;
}