Foxite.COM Community Weblog

Foxite.COM Community Weblog - free weblog service for the Visual FoxPro Community.
Welcome to Foxite.COM Community Weblog Sign in | Join | Help
in
Home Blogs Forum Photos Forum Archives

VFP IMAGING



FUNCTION TO CONVERT COLORS

The short function below converts any color to its darker or brighter version, just as the original colorpicker slidebar.

Parameters:

      RGB - original RGB value to convert

      tnLevel - ranges from -100 to + 100. Zero means no changes; +100 = White; -100 = Black; Positive values will return brighter images, while negative will bring darker.

 

LPARAMETERS tnRGB, tnLevel

IF tnLevel = 0
   RETURN tnRGB
ENDIF

tnLevel = tnLevel / 100

LOCAL lnRed, lnGreen, lnBlue
lnRed   = BITAND(tnRGB, 0x000000FF)
lnGreen = BITRSHIFT(BITAND(tnRGB, 0x0000FF00), 8)
lnBlue  = BITRSHIFT(BITAND(tnRGB, 0x00FF0000), 16)

IF tnLevel > 0
   RETURN RGB( ;
      lnRed   + ((255 - lnRed)   * tnLevel) , ;
      lnGreen + ((255 - lnGreen) * tnLevel) , ;
      lnBlue  + ((255 - lnBlue)  * tnLevel) )
ELSE 
   RETURN RGB( ;
      lnRed   + (lnRed   * tnLevel) , ;
      lnGreen + (lnGreen * tnLevel) , ;
      lnBlue  + (lnBlue  * tnLevel) )
ENDIF

To better understand how it works, you can download the attached file, that contains a simple example. Click on "Select Color" to pick a color then play with the spinner to see the darker and brighter resulting colors.

Published Monday, November 27, 2006 5:18 PM by cesarchalom
Filed Under:
Attachment(s): ChangingColors.zip

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

 

Cesar Chalom said:

January 10, 2007 1:26 AM
 

LuisMaria said:

Este articulo esta traducido al español en www.PortalFox.com

"FUNCION PARA CONVERTIR COLORES"
http://www.portalfox.com/article.php?sid=2301



July 11, 2007 9:20 PM

What do you think?

(required) 
(optional)
(required)