How to Convert Color int to Hex in Ax

Description: There are different coding system for colors. Some functions require the hexadecimal format, others expect an integer and so on.
Luckily, Ax comes with some built in functions to do the necessary conversions for you. Like this one:


WinApi::RGB2int() - Convert the red, green and blue values to an integer.
WinApi::RGBCon2int() - Dito, but with a container input
WinApi::RGBInt2con() - The opposite, converting from an integer to separate red, green and blue values


Or create your own functions, like this one for example:

static void Strint2RGBHex(Args _args)
{
    container colorcon;
    str colorhex;
    int color=16711935;
    ;
    colorcon=WinApi::RGBint2Con(color);
    colorhex=Global::int2Hex(conpeek(colorcon,1),2);
    colorhex+=Global::int2Hex(conpeek(colorcon,2),2);
    colorhex+=Global::int2Hex(conpeek(colorcon,3),2);
    info(strFmt("%1",colorhex));
}

This function will convert an integer color value to a hexadecimal one.

Related Posts

Previous
Next Post »

Thanks for comments.....