Welcome to Foxite.COM Community Weblog Sign in | Join | Help

Bernard Bout

May the Fox be with you...

<September 2006>
SuMoTuWeThFrSa
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567

Post Categories

News

site statistics

Locations of visitors to this page

Navigation

Some VFP links

Others...

Archives

Who links to this site?

Hey There!!!

Syndication




Using the Alpha Channel in Visual Foxpro Images

Using the Alpha Channel in PNG images can result in some very interesting and pleasing effects.

I have been working on some pseudo forms using Alpha Channel masks in PNG images with some very pleasing results. I was not aware that VFP could handle the Alpha channel masks of PNG's so decided to give it a try.

Updated on 12/09/2006 (see below)

I created the images in Paint Shop Pro but any image application like Photoshop etc that can create masks will do. When loaded into a VFP image object these images displayed very interesting effects, so I decided to spend some time exploring this aspect and the following screens are what I came up with. The Titlebar.png is used for the titlebar, mainform.png is used for the main form area. I added the Vistabuttons.bmp and placed invisible command buttons over them for the actions. All are placed into a transparent container into VFP image objects and the other objects like labels, textboxes etc are placed on top. They can be inatantiated using ADDOBJECT( ) onto the form. The images can be saved by right clicking and SavePictureAs.

Titlebar.png

Mainform.png

VistaButtons.bmp

The "forms" are classes with all objects inserted into a transparent container. Once that is done each "form" can be instantiated like any other class.

I say "form" because these are not real forms and do not have the normal form methods, events etc. They are just containers made to look like forms, and can be instantiated in a SDI (Top Level) form. They could be used for data entry or even just for messageboxes.

Here is a form with different objects. The "form" can actually be moved around like a normal form. You can easily see the transparent effect obtained, with the background showing through the title and borders but NOT through the central area. To the right are normal VFP objects placed on the SDI, just to show the difference. Notice the background is visible through the Title bar as well as the borders.

Click any image for a larger view.

This next image shows the form has been moved to partly cover the objects on the right, The Text from those objects is clearly visible through the "form" titlebar.

 

The final image shows the transparent effect achieved, while keeping the main form and objects opaque.

To achieve these effects took about 10 minutes. Less, now that I know how to produce the masks and the effect that can be achieved. With a little more code these can be converted to very modern looking Vista Aero Glass like windows on a humble XP OS.

Now all that's left is for my friend Cesar Chalom to come up with a way of doing this on the fly using GDI+....

Ain't Fox cool?

 

Update - 12th Sept 2006

Cesar has very kindly provided the code to generate the PNG images on the fly. You can get it here:

http://weblogs.foxite.com/cesarchalom/archive/2006/09/12/2445.aspx

This line of code can be changed to whatever size you want. The size here is 300w X 270H

loBitmap = .Bitmap.New(300,270)

Also the central opaque area colour can be changed here:

* Draw the yellow rectangle
loGfx.FillRectangle(.SolidBrush.New(.Color.FromRGB(254,254,228)), 10,9,278,249)

Remember to change the last 2 values to suit your new size - ,278,249)

All that's left now is for Cesar to show us how to make the transparent green PNG. I think it can be done in this line here, by changing the last 3 numbers which is the RGB.

* Make all image transparent
loGfx.Clear(.Color.FromARGB(0,0,0,0))

but I have to leave that to him.

Last tip is to set the image.BorderStyle = 1-Fixed Single. That will give us the opaque outline border of the "form". We are done here.

Thanks Cesar.You are Mr. GDI+ indeed.

Published Monday, September 11, 2006 12:55 AM by bbout

Comments

# re: Using the Alpha Channel in Visual Foxpro Images @ Monday, September 11, 2006 3:54 PM

Hey Bernard !
That's very cool ideed.
What are exactly the images that you want to apply Alpha ?


The green image and the yellow square are both PNG images with an Alpha channel added. If you save them you can open them in a paint program and see.

The yellow square has an Alpha Channel Mask only for the border. The Light Yellow is opaque. This gives the border a transparent look. Basically is it possible to generate the Mainform.png using GDI+?

That's really very easy and simple for GDI+.
Gdi+ works with ARGB colors, where "A" means ALPHA.
For example:
loGfx.DrawRectangle(.SolidBrush.New(.Color.New(128,0,128,0)),x, y, w, h)
where the 1st parameter - 128 means semi-transparency; the other 3 are the common RGB parameters, qith a dark green.

As always, if you need help, just call again !
Hope this helps
Cesar

Cesar Chalom

# re: Using the Alpha Channel in Visual Foxpro Images @ Monday, September 11, 2006 4:03 PM

... Continuing
The new GDI+-X classes provide at least 2 very interesting ways to create and show images on the fly:
1 - Using the Image Canvas object, that is a subclass of the original VFP image control that permits to draw anything on the fly without accessing the disk, only using the memory.
2 - The method "Save" from the Image/Bitmap classes permits to save any image directly to any default VFP Image control, just like this:
loBitmap.Save(Thisform.Image1, .Imaging.ImageFormat.Png)
That's really cool, because the disk is not used, and according to Bo Durban this will provide a gain of performance of about 30 times. The image will be saved to the memory and passed to the "PictureVal" property of the image.

Enter the GDI+X page at codeplex:
http://www.codeplex.com/Wiki/View.aspx?ProjectName=VFPX&title=GDIPlusX and download the latest stable release. Most of the samples use the ImageCanvas object to draw the examples.
You'll find an example of saving an image directly to the Image Object in the sample "ColorChannels.scx"

HTH
Cesar

As always, Thanks Cesar

Cesar Chalom

# Helper code to create image on the fly for &amp;amp;quot;Using the Alpha Channel in Visual Foxpro Images&amp;amp;quot; from Bernard Bout @ Tuesday, September 12, 2006 6:02 AM

Here's another very simple code that attends Bernard Bout, creating an image on the fly, based on his...

Cesar Chalom

# re: Using the Alpha Channel in Visual Foxpro Images @ Tuesday, September 12, 2006 6:07 AM

>>Basically is it possible to generate the Mainform.png using GDI+?

YES, of course !
I couldn't get the original PNG image because Foxite does not allow directly, so I'll show in a simplified way how you could do it:

http://weblogs.foxite.com/cesarchalom/archive/2006/09/12/2445.aspx

Cesar Chalom

# re: Using the Alpha Channel in Visual Foxpro Images @ Tuesday, September 12, 2006 10:02 AM

It's cool!!!

McBern

New Comments to this post are disabled
Powered by Community Server, by Telligent Systems