Improving the VFP Image class with GDI+
The VFP Image base class now has the RotateFlip property where the image set as the Picture property can be rotated and/or flipped.
The different states for the VFP control are:
0 - Rotate0FlipNone
1 - Rotate90FlipNone
2 - Rotate180FlipNone
3 - Rotate270FlipNone
4 - RotateNoneFlipX
5 - Rotate90FlipX
6 - Rotate180FlipX
7 - Rotate270FlipX
(Funnily enough these are exactly the same enumerations in the GDI+x classes.
)
However the Image base class has a problem. It cannot show an image background as transparent if the RotateFlip property is anything other than 0. This can esaily be illustrated in this images below, where the Image control has Backstyle = 0 Transparent

When the RotateFlip is changed to non 0 the background is no longer transparent, even at runtime and this is a big failing.

To the rescue comes the GDI+x classes. Since this is an Image control, all image properties are available that you usually set - Picture, BackStyle, Stretch, RotateFlip etc.
With just a few lines of code inserted in the GDI+x ImgCanvas class we can make sure that our BackStyle setting is respected by the image class at runtime even if the RotateFlip property is non 0.
The attached file (link at bottom) contains this class that will do this for you. All you need to do is drop it on a form, set the normal properties you would set, set a custom property as I will show later on and when the form is run, the image will respect your settings.
In the image below the class is dropped on a form along with normal VFP image base classes. All these objects have the RotateFlip set to 2 - Rotate180FlipNone.

As you can see the controls do not respect the Backstyle property which has been set to 0 - Transparent when the RotateFlip has been changed and this persists even at runtime.
To the left above are two instances of my class and to the right, two instances of the VFP base image class. There are two BMP's involved, one with a white background and the other with a Majenta (RGB(255,0,255) background.
The only properties that need setting, I have added to the Favourites tab. I have also added some MemberData code to the TransparentColour property to allow selection from the VFP Colour Selector, since an integer colour is needed here. Click on the Property and then the button that will appear to change the colour.
The TransparentColour property is the colour that you want to make invisible. In the image on the left it is White and in the image on the right it is Majenta.
The default for the class is White as shown below:

The Image on the right has been changed as shown below, using the button provided.

The result, at runtime is that while the VFP Baseclasses do not handle the BackStyle property at all when RotateFlip is non 0, the GDI+x class with the addition of my code does this very well.

I have barely scratched the surface of these classes. There is scope for many, many improvements for enhancing the functionality of the lowly VFP image base class.
But hold on - There's more. There is one added benefit that this class brings and that again has to do with the BackStyle property of the VFP image class. With the VFP base class, if Backstyle was set to 0 - Transparent, then any pixel of the image that was white (RGB(255,255,255) ) was made completely transparent. A number of images from the web use another colour to signify the transparent colour. So images with colour other than white as background, would not work since you are restricted to white only, with the base class.
In the form below, the same image is assigned to the VFP Base image class on the left and my enhanced class on the right. The BackStyle of both are set to 0 - Transparent. As you can see the backcolour for this image we want to be invisible is Magenta - RGB(255,0,255)

Note that I have changed the TransparentColour property of my class to 16711935 which is the Majenta colour.
At runtime my class does it's work and makes any pixel of the image with that colour transparent as you can see below.

Now that's 2 for the price of one by any reckoning.![Big Smile [:D]](/emoticons/emotion-2.gif)
Note:
As mentioned in other posts,
I dont include the gdiplusc.vcx since you need to download the latest from the VFPx site.
Just open the form in VFP and when it asks you for the Imgcanvas navigate it to the gdiplusx.vcx on your computer. The form will then resolve the location correctly. Save the form, set the default path to the directory where the form is (to find the images) and then run the form. I have subclassed the imgcanvas class from the gdiplusx.vcx class library. Unfortunately this would happen since I don't supply the gdiplusx.vcx and I don't know where a user might have stored it.
Any ideas for further improvement are most welcome.