Convert RGB to Hexadecimal

Posted by Elena_Perello on 10-Jun-2011 05:28

Hi!!

I would need convert a color in RGB to Hexadecimal , how can i do??

Thanks

All Replies

Posted by rohit.ramak on 10-Jun-2011 09:29

Not sure if this will help... but take a look at this thread :  http://communities.progress.com/pcom/message/82076#82076   and look at the function "f_ConvertToHex".

Posted by Elena_Perello on 10-Jun-2011 09:35

Thanks, but I already had seen and not enough for me.
But I've resolved as follows:

PROCEDURE COLOR3:
DEF INPUT PARAMETER i-color AS INT.
DEF OUTPUT PARAMETER o-color AS CHAR.

FOR FIRST ffmzoco WHERE ffmzoco.empre = g_empre AND
                        ffmzoco.hotel = g_hotel AND
                        ffmzoco.ncolor = i-color NO-LOCK:
o-color = '#' + Hexadecimal(INT(ffmzoco.red)) + Hexadecimal(INT(ffmzoco.green)) + Hexadecimal(INT(ffmzoco.blue)).                                         

END.

END PROCEDURE.

FUNCTION Hexadecimal RETURN CHARACTER (i-color AS INT):
    DEF VAR  hNum AS  CHARACTER NO-UNDO  EXTENT  16 INITIAL [ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E' ].
    DEF VAR  chex AS  CHARACTER NO-UNDO.
    DEF VAR  pres AS  INT NO-UNDO.
    DEF VAR  pmod AS  INT NO-UNDO.

    pres = i-color.

    DO WHILE pres > 0:
      ASSIGN pmod = ( pres MOD 16 )
             chex = hNum[pmod + 1] + chex
             pres = ( pres - pmod ) / 16.
    END.
    RETURN chex.


END FUNCTION.

This thread is closed