Board index » cppbuilder » Trasparent Bitmaps : A solution for the masses

Trasparent Bitmaps : A solution for the masses

Here is a simple way to add transparent bitmaps to your C Builder programs,
using no third-part tools:

For this project, create a new application and drop a ImageList Component
onto the form, then save the project.  Open the header file for the Form1
(default is Unit1.h) and
create to Global variables of integer type (int x; int y;)

Click on the ImageList Component (on your form) and then select
dsTransparent in the Drawing Style section of the Object Inspector.

change the size of the Height and Width to accomodate your bitmap

double click on the ImageList component on your form and select ADD
open the bitmap you want and then change the Transparent Color to the color
that
you want to be transparent (this is done in the dialog box that showed up
when you double-clicked the ImageList component on your form)

Then select APPLY and then OK

Click on the Form and then select EVENTS from the Object Inspector
Find the ONPAINT event and add this code:

ImageList1->Draw(Form1->Canvas,(Form1->Width/2)-(ImageList1->Width/2),
        (Form1->Height/2)-(ImageList1->Height/2),0);

This will draw the bitmap with the transparent color to the center of your
form1

To see the actual result, drop some Labels on the Form1 and type in stuff.
(make certain they cross the center of the form so that your image can be
on top of them, otherwise you will not really get the gist of the
transparency)

The only problems that I found with using ImageList Component are these:
        1) Slow draw because it is in Form1->Repaint
        2) Every time you double-click the ImageList component, you must
                reset each of your image transparencies.
        3) All images must be the same size (you can use cropping or stretching)
        4) Any changes to the Object Inspector for the ImageList will make you
                have to reset all the images' tranparencies.
--
Mark A. Malo AKA Particle Man
spammer unfriendly email address (remove iam)
When you know and respect your own inner nature, you know where you belong.
You also know where you do't belong. - Benjamin Hoff

 

Re:Trasparent Bitmaps : A solution for the masses


I just realized that my example is messed up.  This is because prior to
this last post, I had included an attachment that made snse of the global
variables  x and y.  This was because my attachment had routines to allow
user to move the bitmap around the screen.  Without the attachment, it
makes no sense.  Just wanted to clarify.

Other Threads