motifdeveloper.com
Sponsored by IST Limited
Formerly MW3: Motif on the World Wide Web [MW3 Logo]
Last Updated
November 18, 2002
 


X-Designer - The Leading X/Motif GUI Builder - Click to download a FREE evaluation
 

motifdeveloper.com
Home
About the site
Bulletin Board
News Archive
OpenGroup News
Events
Search
Frequently Asked Questions
The Motif FAQ
X/Motif FAQs
General FAQs
Ask Antony
Latest Q & A
All Q & As
Submit Question
Tips & Pointers
Code Examples
Software
OpenMotif
Widget Sets
GUI Toolkits & Libraries
Motif suppliers
Non-commercial S/W
Commercial Software
Multimedia
Miscellaneous
Organizations
Docs & Pubs
X/Motif Newsgroups
Security
Internationalization
Feedback
Feedback Form
Contributors
 

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

 

[IST Limited]
IST Limited is the
proud sponsor of motifdeveloper.com.
 

Thanks to all the contributors to these pages.

Privacy Policy

 
"Motif" is a registered trademark of The Open Group. All other trademarks are the property of their respective owners.

Some articles/papers here have their own copyright notice. All other information is copyright ©1999-2008 IST Limited

[CommerceOne] MW3 site originally by Ken Sall of Commerce One (formerly Century Computing).