I build a mainwindow,and want to display a .jpg or .gif as an icon in the left-top corner,I write code as follows:
main(....)
{
Pixmap icon1;
.......
icon1=XmGetPixmap(XtScreen(toplevel,"/home/icon1.gif",XmUNSPECIFIED_PIXEL,XmUNSPECIFIED_PIXEL);
XtVaSetValues(toplevel,XmNiconPixmap,icon1,NULL);
.........
}
but the picture does not display?What should do ?
Thank you!
Wed, 08/01/2012 - 14:50
#1
Question about display jpg or gif as a icon in a widget?
when I read a .xpm file using above code,it can display,but when .gif or jpg,it can not.Now, how can I do read and display a .gif or .jpg file ? Thanks all.
no body help me?
delmierda
Question about display jpg or gif as a icon in a widget?
I don't know a ton on this subject, but I can tell you what I learned during my exploration of the same problem.
Motif seems to have no support for any image format other than a native X bitmap. This means that in order to display an image on a widget, you must use some library or other code you've written to convert an arbitrary format to a bitmap.
Now, the reason that you were able to display an image using XmGetPixmap with an XPM image is that many (if not all) Motif distributions now include the XPM library (see http://koala.ilog.fr/lehors/xpm.html). Therefore, Motif was doing the conversion for you.
Unfortunately, my company didn't deem the use of images as being useful enough for me to spend any time on implementing any system for converting images and whatnot, but I recommend that you start by taking a look at the ImageMagick library (http://www.imagemagick.org/script/index.php) for help with converting images.
Image Magick does have a library that can be used for all sorts of conversions, but you'll obviously have to follow all of their licensing guidelines on that (I'm no lawyer, sorry).
So, to sum up, you'll have to use some other library (or write your own) to convert JPG, GIF, TIF, etc. images to a format that Motif can handle.
What I wound up doing in the interest of time was to simply install Image Magick's runtime and convert all the images I needed to XPM. I've just been including them in the source files in which they are needed since an XPM image is really just a big string. From there, you can just pass the array into XPM library functions to convert it to the format needed for display.
Hope that helps some.
Or, you can simply install OpenMotif 2.3.
It has support fo JPEG as well as PNG icons (but no GIF).