I found myself needing a way to convert a colour some of the way toward another colour. Possible use cases include
- Lightening or darkening a shade
- Recolouring a palette to match a colour scheme
- Gradients and blends
Now, this is probably a specialised sort of function. With GDI+ (or the .NET System.Drawing) there are better ways to do gradient fills, and transparency may be a more understandable way of doing blending or merging. Still, it was a short function that took a deceptively long time to write, so you might find it useful. (more…)
In New Zealand small change is changing … we’re getting new 50c, 20c and 10c coins, and the 5c coin is being dropped. To match this the guidelines for rounding cash values are also changing.
Previously, the general guidelines were that values were rounded to the nearest 5c - values ending in 1,2,6,7 rounded down, and those ending in 3,4,8,9 were rounding up.
Now we need to round to 10c. However, the New Zealand Retailers Association guidelines state that values ending in 5c (ie exactly in the middle) are to be rounded DOWN (towards zero). This is not conventional mathematical rounding, that you’d find in a function called round() in most programming languages’ standard libraries. So I had to do some work.
(more…)
I can’t remember if there is a method for this buried in _GDIPLUS.VCX or not, but if you don’t want to use a GpColor object just to convert colours, the following tiny function would do:
function FoxRGBToARGB( tnRGB as integer, tnAlpha as integer )
return ;
bitor( bitlshift(bitand(iif(vartype(m.tnAlpha)=='N', m.tnAlpha, 0xFF), 0xFF ),24) ;
, bitlshift(bitand(m.tnRGB,0xFF),16) ;
, bitand(m.tnRGB,0x0000FF00) ;
, bitrshift(bitand(m.tnRGB,0x00FF0000),16) )
Example use:
m.foxrgb = getcolor()
m.argb = FoxRGBToARGB( m.foxrgb, 0xFF )
? transform(argb,'@0')
This technique is basically lifted from the foxrgb_assign method from the GpColor class, plus adding in the alpha value
This is the story of a useful little utility function to extract the “first line” out of a block of multi-line text. If all you want is the function, then you can stop on the first page. If you’re interested in how someone can spend an hour writing a simple function that is less than 25 lines long, and why it ended up how it is, then read to the gory end!
function GetFirstLine( tcText [, tnMaxLen] [, tcEllipses] )
(more…)