将RGBA转换为十六进制或ARGB转换为十六进制 [英] Convert RGBA to Hex or ARGB to Hex

查看:999
本文介绍了将RGBA转换为十六进制或ARGB转换为十六进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将Flash应用程序中的十进制颜色代码转换为HTML显示的十六进制颜色代码

我有这些数字它们是8位数字,但我不确定它们是ARGB还是RGBA。有没有一种方法可以从颜色代码本身了解这一点?



我有一个javascript函数可以将十进制转换为十六进制数字,但我没有补偿值(或删除它)。你能帮我修复我的函数,从RGB十进制代码中提取/去除A值吗?



$ p $函数decimalToHex(num)
{
if(num == null || num ==undefined){return0xFFFFFF; }

var intNum =(parseInt(num,10))& 8; / /这是否删除最重要的8位?
return intNum.toString(16);


解决方案

最高字节,然后按位AND与0x00FFFFFF删除。所以:


var intNum =(parseInt(num,10))&至0x00FFFFFF;



或者,如果alpha值在最低字节中,则按位AND与0xFFFFFF00,然后右移8: p>


var intNum =(parseInt(num,10)& 0xFFFFFF00)>> 8;


I am trying to convert a decimal colour code from a Flash Application into a hexadecimal colour code for HTML display

I have these numbers which are 8 digits long, but I am not sure if they are ARGB or RGBA. Is there a way to figure this out from the colour codes themselves?

I have a javascript function that can convert a decimal to a hexadecimal number but I am not compensating for the A value(or removing it). Can you help me fix my function to extract/remove the A value from the RGB decimal code?

function decimalToHex( num )
{
  if (num == null || num == "undefined") { return "0xFFFFFF"; }

  var intNum = (parseInt(num,10)) & 8;  // does this remove the most significant 8 bits?
  return intNum.toString(16);
}

解决方案

If the alpha value is in the highest byte, then bitwise AND with 0x00FFFFFF to remove that. So:

var intNum = (parseInt(num,10)) & 0x00FFFFFF;

Or, if the alpha value is in the lowest byte, bitwise AND with 0xFFFFFF00, then shift right 8:

var intNum = (parseInt(num,10) & 0xFFFFFF00) >> 8;

这篇关于将RGBA转换为十六进制或ARGB转换为十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆