admin管理员组文章数量:1026989
I have an 8-bit hex decimal which is in aarrggbb
format. I need methods to convert this to rrggbbaa
format and vise versa. For eg
ARGB format
#FFFF2323
What i need is RGBA format
#FF2323FF
I have an 8-bit hex decimal which is in aarrggbb
format. I need methods to convert this to rrggbbaa
format and vise versa. For eg
ARGB format
#FFFF2323
What i need is RGBA format
#FF2323FF
-
3
so, you have a string #FFFF2323? you want
'#FFFF2323'.replace(/#(..)(......)/, '#$2$1')
– Jaromanda X Commented Jun 26, 2018 at 7:41 - @JaromandaX Very elegant solution. Please make it an answer to the question :-) – Emil S. Jørgensen Commented Jun 26, 2018 at 7:45
- where did that non regex answer go! It was fine – Jaromanda X Commented Jun 26, 2018 at 7:51
2 Answers
Reset to default 5If you're dealing with a string #FF123456
let x = '#FF123456';
console.log(x.replace(/#(..)(......)/, '#$2$1'));
If, however, x is a number, 0xFF123456 -
let x = 0xFF123456
console.log(`#${(x & 0x0FFFFFF).toString(16).padStart(6, '0')}${(x >>> 24).toString(16).padStart(2, '0')}`);
All you have to do is move a[1] and a[2] to the end
var a = "#AABBCCDD";
var b = "#"+a.slice(3,9)+a[1]+a[2];
I have an 8-bit hex decimal which is in aarrggbb
format. I need methods to convert this to rrggbbaa
format and vise versa. For eg
ARGB format
#FFFF2323
What i need is RGBA format
#FF2323FF
I have an 8-bit hex decimal which is in aarrggbb
format. I need methods to convert this to rrggbbaa
format and vise versa. For eg
ARGB format
#FFFF2323
What i need is RGBA format
#FF2323FF
-
3
so, you have a string #FFFF2323? you want
'#FFFF2323'.replace(/#(..)(......)/, '#$2$1')
– Jaromanda X Commented Jun 26, 2018 at 7:41 - @JaromandaX Very elegant solution. Please make it an answer to the question :-) – Emil S. Jørgensen Commented Jun 26, 2018 at 7:45
- where did that non regex answer go! It was fine – Jaromanda X Commented Jun 26, 2018 at 7:51
2 Answers
Reset to default 5If you're dealing with a string #FF123456
let x = '#FF123456';
console.log(x.replace(/#(..)(......)/, '#$2$1'));
If, however, x is a number, 0xFF123456 -
let x = 0xFF123456
console.log(`#${(x & 0x0FFFFFF).toString(16).padStart(6, '0')}${(x >>> 24).toString(16).padStart(2, '0')}`);
All you have to do is move a[1] and a[2] to the end
var a = "#AABBCCDD";
var b = "#"+a.slice(3,9)+a[1]+a[2];
本文标签: javascriptConvert ARGB to RGBA formatStack Overflow
版权声明:本文标题:javascript - Convert ARGB to RGBA format - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745657770a2161700.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论