SA-MP Forums Archive
hex to rgba. - 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)
+--- Thread: hex to rgba. (/showthread.php?tid=447937)



hex to rgba. - audriuxxx - 02.07.2013

Hi,

How from hex for ex: 080808
Make RGBA? i want to use that in setobjectmaterialtext...


Re: hex to rgba. - Bakr - 02.07.2013

You need to extract the channels with bitwise operations.

pawn Код:
new value = 0xFFFFFFFF; // value to extract channels from

new red = (value & 0xFF000000) >> 24;
new green = (value & 0x00FF0000) >> 16;
new blue = (value & 0x0000FF00) >> 8;



Re: hex to rgba. - audriuxxx - 02.07.2013

And how to use red, green, blue new's?


Re: hex to rgba. - Bakr - 02.07.2013

You pass that function a hexadecimal, just in the format of ARGB instead of RGBA. You can switch the R and A values like so:
pawn Код:
new color = 0xFFFFFFAA; // original color

new r = (color & 0xFF000000) >> 24;
new g = (color & 0x00FF0000) >> 16;
new b = (color & 0x0000FF00) >> 8;
new a = (color & 0x000000FF);

// the new color that you pass to SetObjectMaterialText
new value = ( ((a & 0xFF) << 24) | ((g & 0xFF) << 16) | ((b & 0xFF) << 8) | (r & 0xFF) );