New version of GradObjects

I've just posted a new version of the GradObjects class.
Nhanks to Nigel for reporting a bug that occured when using graphical OptionGroups.
Here's the updated version.

GradObjects Download - Release 2020

More info can be obtained at the original post:
GradObjects Revisited - 2020


GETPICT() with thumbnails

I've seen in many forums people asking about the possibility to open the getpict() dialog showing thumbnails instead of picture file names.

Just for fun, I did some tests simulating some keystrokes, and it works ! Save the 3 lines below in a PRG and run under WinXP:

oShell = CREATEOBJECT("Wscript.Shell")

The SendKeys function from WSH was used - at this link you can find all key codes, if you want to use this technique for any other purpose: http://msdn2.microsoft.com/en-us/library/system.windows.forms.sendkeys(vs.71).aspx

This was tested only in my working machine, under winxp professional. it probably does not work this way in other OS's so be careful, and if you want to use this code, check this first.

I'm almost sure that there must be another way, probably safer to do that. Do you know any?


Blur Images with GdiPlus X

blurring images is also very easy.

the simplest technique is to resize the original image to a much smaller size, and then resize it to the original size.

the reason is very obvious, when we enhance the dimensions of any image we have a loss of quality, causing the blur effect.


requires vfp9 and gdiplusx to run. 
please make sure that you have the latest version!


* init gdiplusx
do locfile("system.app")

with _screen.system.drawing

* load source image
local lobmp as xfcbitmap
lobmp = .

* get a rectangle with the bitmap dimensions
local lorect as xfcrectangle
lorect = lobmp.getbounds()

* initialize the graphics object to be able to draw in the image
local logfx as xfcgraphics
logfx = .graphics.fromimage(lobmp)

local lnreducefactor as integer
lnreducefactor = 10 && the image will be reduced in 10 times

* get the thumbnail with the desired size
local lodestbmp as xfcimage
lodestbmp = lobmp.getthumbnailimage(lobmp.
width / lnreducefactor, lobmp.height / lnreducefactor)
* draw the image, showing the intensity of the cyan channel.
logfx.drawimage(lodestbmp, lorect)
save("c:\blurred.jpg", .imaging.imageformat.jpeg)

/n explorer.exe c:\blurred.jpg



 original image 


 factor = 4 

factor = 8

factor = 8

factor = 12

factor = 20



original image

factor = 4

factor = 8

factor = 12

factor = 20


Rotate and Flip images with GdiPlusX

Here's some adapted code from a previous post that used _gdiplus.vcx, but this time using gdiplusx:

Rotating and / or flipping images is a very simple task for gdi+. To see the different results possible, change the constant value in the variable lnEnumRotateFlip in the code below.


Requires VFP9 and GdiplusX to run.  



* Init GdiPlusX
DO System.app

LOCAL loBmp as xfcBitmap
LOCAL lnEnumRotateFlip


loBmp = .Bitmap.FromFile(GETPICT())
lnEnumRotateFlip = .RotateFlipType.Rotate90FlipNone  && change this value with the presented below

* to save the image as png
loBmp.Save("c:\RotateFlip.png", .imaging.imageformat.png)

RUN /N EXPLORER.EXE RotateFlip.png


rotatenoneflipnone 0  

rotate90flipnone   1  

rotate180flipnone  2  

rotate270flipnone  3  

rotatenoneflipx    4  

rotate90flipx      5  

rotate180flipx     6  

rotate270flipx     7  


Bo Durban is blogging !!!

I'm very happy to announce that my guru, Bo Durban, has just started his blog.


Working with him in the GdiplusX library has been very inspiring, exciting and pleasant. I've really learned a lot with him in the last year.

Don't forget to update your readers, because Bo's stuff is genius !

Welcome to the blogosphere Bo!


VFPPaint - Flexible Drawing and Paint utility with GdiPlus X

sometimes users need to make some basic modifications in images that are part of the application, and it is not comfortable for them too have to look for files, choose places to save, etc... in the vast majority of cases, ms-paint does the job, but i always needed it to be customized... and i couldn't.

after being challenged by frank cazabon in a foxite thread, i finally took the courage to create my own "paint" application, using gdi+.

vfppaint works much like mspaint, and creates a canvas that permits you to draw whatever you want with the mouse.

it's just one single 50k scx file that does all the job, in partnership with the gdiplusx library.

requires vfp9 and gdiplusx to run. 
the latest stable version of gdiplusx is dated 11th may 2007 - alpha 0.8a. please make sure that you have the latest version, because vfppaint uses some functions that were added recently.

when you run vfppaint.scx it will ask you to select the folder where gdiplusx library is located.


- draw points, rectangles lines and ellipses with the mouse.

- text drawing, choose any font, size and style, and it will appear at the place that you click on the image. (drag and drop to choose the best place)

- choose any color, from the palette or directly from the loaded image or canvas and select the pen width that you want to draw.

- select the shape or type of drawing in the graphical option buttons, and then go to the canvas (image object) and click the left mouse button.

- drag and drop is available for rectangles, lines and ellipses.

- basic undo features

- rotate and flip images

- resizing images

- printing and saving images


basic commands:

load image to canvas
save image in desired image format
print image
undo last changes
pick color from palette
pick color from canvas
clear entire canvas with selected color
rotate left
rotate right
flip image horizontally
flip image vertically
draw points
draw rectangle
draw ellipse
draw line
fill rectangle
fill ellipse
draw string
resize image
select font, size and type


all images are generated without disk access, using the new pictureval property of the image control. for this specific case, i didn't use the imagecanvas that ships with gdiplusx because i needed some extra customization. after the latest release of gdiplusx, getting the pictureval property of an image has became very simplified, with the new methods added to the image class - getpictureval and getpicturevalfromhbitmap.

as sometimes we need to work with an image that is bigger than our screen,  the drawing canvas was put in a "in toplevelform" that has scrollbars.

another cool feature is the "undo" possibilities. vfppaint stores the previous bitmap in a cache. this can be improved too, maybe you need to "undo" in higher level. for this, very few code is needed.

when drawing on the canvas, try dragging and dropping the objects. for this, the "undo" feature was highly used, because the shape is drawn, and when the user moves the mouse, it restores the original image from the buffer and draws again in the new position.


when a big sized image is loaded, first it asks if the canvas needs to be resized.

scrollbars appear in the image to help dealing with it. in a first moment, i thought of using the very nice ctl32 scrollable container from carlos aloatti and malcolm greene, but i gave up because i needed the pictureval property, that is present only in the default image control. so, there are currently 2 forms in the screenshot below. one is a "in toplevel" form that contains just one image object, and resides in the main vfppaint form. the other form is a "toplevel form". the image object from the "child form" changes its size automatically, depending on the image dimensions. when this object is resized, the child form automatically resizes itself, and shows and adjusts the scrollbars if needed.


resizing sample:


vfppaint also accepts that you pass an image file as a parameter. this way, you'll be able to open the form loading automatically the desired image to edit. run the form like this:

do form vfppaint with "eyes.gif"

in case you pass a gif image as a parameter, it will be automatically converted to 24bpp. that's because gifs are indexed images. a classic example of indexed images are monochrome. pure monochrome images use only 1 bit per pixel. so, in just one byte you can store information of 8 pixels ! in the case of gifs, they are usually 8 bits per pixel, so in one bit we can have a value that ranges from 0 to 255 - that's exactly the quantity of colors supported by gifs ! unfortunately, the redistributable version of gdi+ has a limitation when working with images created in indexed pixel formats, such as 1bppindexed (0x00030101), 4bppindexed (0x00030402) and 8bppindexed (0x00030803). if you try to draw on this kind of images you'll always receive an error message when you'll create the graphics object, that permits to you to draw on the image. more detailed info about this can be found in this post: drawing on gifs or indexed pixel format images with gdi+  http://weblogs.foxite.com/vfpimaging/archive/2006/03/18/1302.aspx . that's why gifs are converted to a 24bpp format before initializing the painting possibilities.

this still has a lot that can be improved, like adding special effects, such as brightness, contrast, hue adjustments, cutting and pasting image portions, saving and retrieving images or pieces of image in the clipboard, etc.

but the main thing is that this totally customizable. the more important in this form is the technique that was used, and you'll see that there's not too much code there.

this still needs to be more tested. feel free to call me if you find any problems or have suggestions. maybe some of your needs can be of interest to be added to vfppaint, and i'll be happy to improve it.

any feedback is very welcome!