HEX to Alpha Red Green Blue
#1

Hello guys,

Does anybody of you know how I can convert (by a pawn script) the HEX code to ARGB?
Ex:

I have: 0xFF0000FF
This should be converted into:

Red = 255
Green = 0
Blue = 0
Alpha = 255

I hope you understand my question, and I hope that someone can help me with this.
Thank you.


Jeffry
Reply
#2

You need color Codes for pawno??
Reply
#3

Quote:
Originally Posted by Harry_Sandhu
View Post
You need color Codes for pawno??
No, I need to convert the HEXADECIMAL color code into a ARGB (Alpha Green Red Blue) variables.
Reply
#4

pawn Code:
stock get_rgba(color, &r, &g, &b, &a) {
    r = (color & 0xFF000000) >>> 24;
    g = (color & 0x00FF0000) >>> 16;
    b = (color & 0x0000FF00) >>> 8;
    a = (color & 0x000000FF);
}
Small test:

pawn Code:
new color = 0xAABBCCDD;
new red, green, blue, alpha;
get_rgba(color, red, green, blue, alpha);

printf("red: %x\ngreen: %x\nblue: %x\nalpha: %x",
    red, green, blue, alpha);
Reply
#5

Thanks alot.
May I use this in a future release? You'd get /credits for sure. ^^

EDIT: If I may ask: Do you know how I can do it the other way round? Means from RGBA to HEX?

Jeffry
Reply
#6

Quote:
Originally Posted by Jeffry
View Post
Thanks alot.
May I use this in a future release? You'd get /credits for sure. ^^
Sure

Quote:
Originally Posted by Jeffry
View Post
EDIT: If I may ask: Do you know how I can do it the other way round? Means from RGBA to HEX?

Jeffry
pawn Code:
stock make_color(r, g, b, a) {
    new color = 0;
    color |= (r & 0xFF) << 24;
    color |= (g & 0xFF) << 16;
    color |= (b & 0xFF) << 8;
    color |= (a & 0xFF);
    return color;
}
Reply
#7

Great, awesome!
Thank you very very much!

+1 Rep for you.

Jeffry
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)