Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!raybed2!hsd From: hsd@raybed2.msd.ray.com (HERBERT DASILVA) Newsgroups: comp.windows.x.motif Subject: Re: bitmap Keywords: bitmap pixmap image Message-ID: <2228@raybed2.msd.ray.com> Date: 22 Apr 91 15:01:28 GMT References: <31@kivax.UUCP> Organization: Raytheon Company, Tewksbury, Mass. Lines: 85 In article <31@kivax.UUCP> koe@kivax.UUCP (Diana Koehler) writes: >Hello, >I have several bitmaps (created with a scanner) and I want to display >them within a Motif-Application. I'll explain this last... >How does the bitmap have to be formatted, that it can be interpreted >by Motif-applications. The bitmap should be in 'xbm' format. This is the format output by the standard X11 tool 'bitmap'. >(f.e Some times ago I have seen the picture of a mandrill. I think > that the bitmap is NOT created with the bitmap editor "bitmap".) The mandrill is NOT a bitmap, it is a PIXMAP. A bitmap is just that, a two dimensional 'map' (read array) of bits (1s and 0s, on and off). A pixmap has color data encoded at each pixel location in the 'map'. >Does there exist an other tool for creating bitmaps? Probably, but I don't know of any off hand. >Any help would be apreciate. >Thanks in advance >Diana To display a bitmap in a Motif application is pretty easy, you display it in an XmLabel (or XmLabelGadget) like this: Since bitmaps contain no color, you must choose two colors, a foreground and a background color. You do this by allocating the colors: Display *display; XColor *bgColor; /* Actual color values for the color requested */ XColor *fgColor; XColor *bgScreenColor; /* Closest color the display can actually produce */ XColor *fgScreenColor; bgColor = (XColor *)malloc( sizeof( XColor ) ); fgColor = (XColor *)malloc( sizeof( XColor ) ); bgScreenColor = (XColor *)malloc( sizeof( XColor ) ); fgScreenColor = (XColor *)malloc( sizeof( XColor ) ); display = XtDisplay( widget ); sts = XLookupColor( display, DefaultColormap( display, DefaultScreen(display) ), "black", bgColor, bgScreenColor ); sts = XLookupColor( display, DefaultColormap( display, DefaultScreen(display) ), "white", fgColor, fgScreenColor ); free( bgColor ); free( fgColor ); Then create a pixmap from the 'xbm' bitmap file: Pixmap pixmap; pixmap = XmGetPixmap( XtScreen(widget), "/usr/your/path/bitmap.xbm", fgScreenColor->pixel, bgScreenColor->pixel ); free( fgScreenColor ); free( bgScreenColor ); Then create the label with the pixmap in it: ac = 0; XtSetArg( args[ac], XmNlabelType, XmPIXMAP ); ac++; XtSetArg( args[ac], XmNlabelPixmap, pixmap ); ac++; pixWidget = XmCreateLabel( parent, "LabelPixmap", args, ac ); XtManageChild( pixWidget ); Ta Da! Instant bitmap. A Truly Impressive addition to any program. Any questions or problems, don't hesitate to ask. Herb DaSilva