Image in Motif App - Motif

This is a discussion on Image in Motif App - Motif ; Hi, I'm kinda new to this Motif game, having used MFC for a while. I need to get a colour image into my Motif application, and having googled around, understand I do this using a label and setting the corrects ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Image in Motif App

  1. Image in Motif App

    Hi,
    I'm kinda new to this Motif game, having used MFC for a while.
    I need to get a colour image into my Motif application, and having
    googled around, understand I do this using a label and setting the
    corrects args in that label widget. However, I'm really confused by a
    number of things, and having looked around can't find any example code
    ANYWHERE, and unhelpful replies to NG posts like "look in the FAQ" (I
    have, I can't find it).
    Could someone post a small code sample showing how to get abc.bmp (or
    whatever format) into my motif app with my topmost widget called
    top_widget?
    Many thanks,
    Phil

  2. Re: Image in Motif App

    Phil Parsonage wrote:

    > Hi,
    > I'm kinda new to this Motif game, having used MFC for a while.
    > I need to get a colour image into


    Please define "into" more precisely.

    > my Motif application, and having
    > googled around, understand I do this using a label and setting the
    > corrects args in that label widget. However, I'm really confused by a
    > number of things, and having looked around can't find any example code
    > ANYWHERE, and unhelpful replies to NG posts like "look in the FAQ" (I
    > have, I can't find it).


    I would suggest FAQ topic 136) TOPIC: ICON WIDGET and PIXMAPS.

    > Could someone post a small code sample showing how to get abc.bmp (or
    > whatever format) into my motif app with my topmost widget called
    > top_widget?
    > Many thanks,
    > Phil



    --
    Michel Bardiaux
    Peaktime Belgium S.A. Bd. du Souverain, 191 B-1160 Bruxelles
    Tel : +32 2 790.29.41


  3. Re: Image in Motif App

    OK, I've tried again to write some code. "montor.xpm" is one of the
    standard xpms in the X11 folders.

    Widget up; //Been created and managed elsewhere...trust me.

    XpmAttributes attributes;
    Colormap colormap = DefaultColormap(XtDisplay(up),
    DefaultScreen(XtDisplay(up)));

    attributes.valuemask = XpmColormap | XpmCloseness | XpmSize;
    attributes.closeness = 50000;
    attributes.exactColors = false;
    attributes.colormap = colormap;

    Pixmap p;
    int check = XpmReadFileToPixmap(XtDisplay(up),DefaultRootWindo w(XtDisplay(up)),
    "monitor.xpm",&p,NULL,&attributes);
    printf("Check = %d",check);
    fflush(stdout);
    Widget picture = XtVaCreateManagedWidget("Picture",
    xmLabelWidgetClass, across1, XmNlabelPixmap, &p, NULL);


    I get NO error message, no crash, just "Picture" dumped on the label.

  4. Re: Image in Motif App

    Phil Parsonage wrote:

    > OK, I've tried again to write some code. "montor.xpm" is one of the
    > standard xpms in the X11 folders.
    >
    > Widget up; //Been created and managed elsewhere...trust me.
    >
    > XpmAttributes attributes;
    > Colormap colormap = DefaultColormap(XtDisplay(up),
    > DefaultScreen(XtDisplay(up)));
    >
    > attributes.valuemask = XpmColormap | XpmCloseness | XpmSize;
    > attributes.closeness = 50000;
    > attributes.exactColors = false;
    > attributes.colormap = colormap;
    >
    > Pixmap p;
    > int check = XpmReadFileToPixmap(XtDisplay(up),DefaultRootWindo w(XtDisplay(up)),
    > "monitor.xpm",&p,NULL,&attributes);
    > printf("Check = %d",check);
    > fflush(stdout);
    > Widget picture = XtVaCreateManagedWidget("Picture",
    > xmLabelWidgetClass, across1, XmNlabelPixmap, &p, NULL);
    >
    >
    > I get NO error message, no crash, just "Picture" dumped on the label.


    RTFM:
    XmNlabelPixmap
    Specifies the pixmap when XmNlabelType is XmPIXMAP

    --
    Michel Bardiaux
    Peaktime Belgium S.A. Bd. du Souverain, 191 B-1160 Bruxelles
    Tel : +32 2 790.29.41


  5. Re: Image in Motif App

    Thanks Michel for the effort, but I had already looked in the FAQ. I
    think what you meant in your last post (I still had to figure this out
    for myself) was that I also has to set XmNlabelType to XmPIXMAP when I
    created Widget picture.
    Therefore, the code for all those of you that want to cut and paste
    is:


    XpmAttributes attributes;
    Colormap colormap = DefaultColormap(XtDisplay(across1),
    DefaultScreen(XtDisplay(across1)));

    attributes.valuemask = XpmColormap | XpmCloseness | XpmSize;
    attributes.closeness = 50000;
    attributes.exactColors = false;
    attributes.colormap = colormap;

    Pixmap p;
    int check = XpmReadFileToPixmap(XtDisplay(across1),DefaultRoot Window(XtDisplay(across1)),
    "./res/Logo64x64.xpm",&p,NULL,&attributes);
    Widget picture = XtVaCreateManagedWidget("Picture",
    xmLabelWidgetClass, across2, XmNlabelPixmap, p, XmNlabelType,
    XmPIXMAP, NULL);


    Hope that helps anyone with a similar problem in the future.

  6. Re: Image in Motif App



    Phil Parsonage wrote:
    >
    > Thanks Michel for the effort, but I had already looked in the FAQ. I
    > think what you meant in your last post (I still had to figure this out
    > for myself) was that I also has to set XmNlabelType to XmPIXMAP when I
    > created Widget picture.
    > Therefore, the code for all those of you that want to cut and paste
    > is:
    >
    > XpmAttributes attributes;
    > Colormap colormap = DefaultColormap(XtDisplay(across1),
    > DefaultScreen(XtDisplay(across1)));
    >
    > attributes.valuemask = XpmColormap | XpmCloseness | XpmSize;
    > attributes.closeness = 50000;
    > attributes.exactColors = false;
    > attributes.colormap = colormap;
    >
    > Pixmap p;
    > int check = XpmReadFileToPixmap(XtDisplay(across1),DefaultRoot Window(XtDisplay(across1)),
    > "./res/Logo64x64.xpm",&p,NULL,&attributes);
    > Widget picture = XtVaCreateManagedWidget("Picture",
    > xmLabelWidgetClass, across2, XmNlabelPixmap, p, XmNlabelType,
    > XmPIXMAP, NULL);
    >
    > Hope that helps anyone with a similar problem in the future.


    Here's another way to do it by including the xmp file in your source
    code. This is useful when you are using a fixed pixmap (rather than a
    dynamic one that may vary from execution to execution):

    #include "pixmapName.xpm"

    XpmAttributes attributes;
    int status;
    Pixmap pixmap;

    XtVaGetValues( widget,
    XmNdepth, &(attributes.depth),
    XmNcolormap, &(attributes.colormap),
    NULL );
    attributes.visual = DefaultVisual(XtDisplay(widget),
    DefaultScreen(XtDisplay(widget)));
    attributes.valuemask = (XpmDepth | XpmColormap | XpmVisual);

    status = XpmCreatePixmapFromData(XtDisplay(widget),
    DefaultRootWindow(XtDisplay(widget)),
    pixmapName, &pixmap, NULL,
    &attributes);

    Here, "pixmapName" is the char** variable named in the xpm file, and
    "widget" is the widget you want to display it in (or its parent, or the
    top level shell, etc.).

    --
    Fred L. Kleinschmidt
    Boeing Associate Technical Fellow
    Technical Architect, Common User Interface Services
    M/S 2R-94 (206)544-5225

  7. Re: Image in Motif App

    Phil Parsonage wrote:

    > Thanks Michel for the effort, but I had already looked in the FAQ. I
    > think what you meant in your last post (I still had to figure this out
    > for myself) was that I also has to set XmNlabelType to XmPIXMAP when I
    > created Widget picture.
    > Therefore, the code for all those of you that want to cut and paste
    > is:
    >
    >
    > XpmAttributes attributes;
    > Colormap colormap = DefaultColormap(XtDisplay(across1),
    > DefaultScreen(XtDisplay(across1)));
    >
    > attributes.valuemask = XpmColormap | XpmCloseness | XpmSize;
    > attributes.closeness = 50000;
    > attributes.exactColors = false;
    > attributes.colormap = colormap;
    >
    > Pixmap p;
    > int check = XpmReadFileToPixmap(XtDisplay(across1),DefaultRoot Window(XtDisplay(across1)),
    > "./res/Logo64x64.xpm",&p,NULL,&attributes);
    > Widget picture = XtVaCreateManagedWidget("Picture",
    > xmLabelWidgetClass, across2, XmNlabelPixmap, p, XmNlabelType,
    > XmPIXMAP, NULL);
    >
    >
    > Hope that helps anyone with a similar problem in the future.


    Does it work? If not, (1) what is the problem (2) please post a complete
    test harness.

    --
    Michel Bardiaux
    Peaktime Belgium S.A. Bd. du Souverain, 191 B-1160 Bruxelles
    Tel : +32 2 790.29.41


+ Reply to Thread