updated code - fixed bug reported by jean pierre senet in the graphics initialization. merci beaucup jean !
the function below converts any button image to a bmp to be used in vfp forms.
there are lots of cool and free icons available on the web, but the vast majority are in .ico, gif or png image formats, that are not very familiar and reliable to be used in vfp. for us, the best image format, for a lot of reasons, is the bmp format.
some transformations are needed to make this bmp to show exactly how we desire, specially when converting source images in a png, gif or ico formats.
vfp shows the pure white - rgb(255,255,255) as transparent in our buttons and image objects. the code below first converts the original whites to rgb(254,254,254) that is visually the same, but does not become transparent, and eliminates the need to create a mask image (.msk) and next, converts the background color of the original bitmap to pure white, that will show transparent in vfp forms.
for more details, please check these prior posts:
requires vfp9 and gdiplusx to run.
please make sure that you have the latest version, because this sample may be using some functions that were added or fixed recently.
save the program below as button2bmp.prg, and call it this way:
when you compile this program in your executable, please don't dorget to remove the locfile() command, and just use a do system.prg instead
lparameters tcsourcefile, tcdestfile
local lobmp as xfcbitmap
local logfx as xfcgraphics
local loborderclr as xfccolor
local lorect as xfcrectangle
local loattr as xfcimageattributes
local locolormap as xfccolormap
locolormap = .imaging.colormap.new()
loattr = .imaging.imageattributes.new()
lobmp = .bitmap.fromfile(tcsourcefile)
logfx = .graphics.fromimage(lobmp)
lorect = lobmp.getbounds()
* get the top left pixel color, presuming this color is the background colro to become transparent
* for our bmp case, this will become pure white - rgb(255,255,255)
* that becomes transparent when used in vfp objects
loborderclr = lobmp.getpixel(0,0)
* convert original whites rgb(255,255,255) to off white - rgb(254,254,254)
* this way, the whites will remain without the need of a mask
locolormap.oldcolor = .color.white
locolormap.newcolor = .color.fromargb(255,254,254,254)
logfx.drawimage(lobmp, lorect, lorect, .graphicsunit.pixel, loattr)
* next step, convert the borders to pure white, rgb(255,255,255) that will become transparent in buttons
locolormap.oldcolor = loborderclr
locolormap.newcolor = .color.white
logfx.drawimage(lobmp, m.lorect, m.lorect, .graphicsunit.pixel, loattr)