SA-MP Forums Archive
HEX to Alpha Red Green Blue - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: HEX to Alpha Red Green Blue (/showthread.php?tid=268417)



HEX to Alpha Red Green Blue - Jeffry - 12.07.2011

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


Re: HEX to Alpha Red Green Blue - Harry_Sandhu - 12.07.2011

You need color Codes for pawno??


Re: HEX to Alpha Red Green Blue - Jeffry - 12.07.2011

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.


Re: HEX to Alpha Red Green Blue - 0x5A656578 - 12.07.2011

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);



Re: HEX to Alpha Red Green Blue - Jeffry - 12.07.2011

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


Re: HEX to Alpha Red Green Blue - 0x5A656578 - 12.07.2011

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;
}



Re: HEX to Alpha Red Green Blue - Jeffry - 12.07.2011

Great, awesome!
Thank you very very much!

+1 Rep for you.

Jeffry