How can I create a pixmap with a transparent background?
|
24-Jul-02 16:00 GMT
|
Question: How can I display pixmaps so that the background is transparent and just
the foreground of the image displayed?
There are two stages to achieving this. The first involves the creation of
a correctly formatted pixmap. The second step involves some coding.
The key requirement for the pixmap itself is a symbolic link to a color.
For example, you need to give the color "none" a symbolic reference. This
reference can be anything provided that the color "none" has the following
definition:
". s Test c none",
the s being the symbolic link and the "c" meaning color. An example pixmap
using this syntax is as follows:
static char *mypix_icon [] = {
"24 24 3 1",
" c #000000",
". s Test c none",
"o c #ff0000",
"........................",
"........................",
"........................",
"........................",
"......... .........",
"........ oooooo ........",
"....... oooooooo .......",
"...... oooooooooo ......",
"...... oooooooooo ......",
"..... oooooooooooo .....",
"..... oooo....oooo .....",
"..... oooo....oooo .....",
"..... oooo....oooo .....",
"..... oooooooooooo .....",
"...... oooooooooo ......",
"...... oooooooooo ......",
"....... oooooooo .......",
"........ oooooo ........",
"......... .........",
"........................",
"........................",
"........................",
"........................",
"........................"
};
As far as the required code is concerned the following function sets up the
background color of the pixmap accordingly:
#include <xpm.h>
static void Transparent_Object ( Widget The_Object,
char *Transparent_icon[], Pixmap *Test)
{
XpmAttributes XpmAttr;
int Depth;
Pixel Background= 0;
static XpmColorSymbol XpmTransparentColor[1] =
{{ NULL, "none", 0 }};
XtVaGetValues(The_Object, XmNdepth,&Depth, XmNbackground,
&Background,NULL);
XpmTransparentColor[0].pixel = Background;
XpmAttr.valuemask = XpmColorSymbols | XpmCloseness | XpmDepth;
XpmAttr.colorsymbols = XpmTransparentColor;
XpmAttr.numsymbols = 1;
XpmAttr.closeness = 65535;
XpmAttr.depth = Depth;
XpmCreatePixmapFromData( XtDisplay( The_Object ),
DefaultRootWindow( XtDisplay(The_Object) ),
Transparent_icon, Test, NULL, &XpmAttr );
}
The syntax for this call is as follows:
Transparent_Object(Widget Name, Pixmap Name, Pixmap Address);
The basis of the method used is to grab the background colour of the object
that you wish to put your image onto and make the pixmap background colour
the same. To do this, you will need to make a call to the function after
the object has been created:
button1 = XmCreatePushButton (shell1, (char *)"button1", al, ac );
Transparent_Object (button1, mypix_icon, &pixmap_resources.mypix);
Once you've implemented this you should find that your pixmap background is
now transparent.
Sponsored
by X-Designer - The Leading X/Motif GUI Builder
- Click to download a FREE evaluation
Goto top of page
|