# Having trouble showing BMP images in XPCE (Unix/X11)

**URL:** <https://swi-prolog.discourse.group/t/having-trouble-showing-bmp-images-in-xpce-unix-x11/6591>\
**Category:** Help!\
**Created:** [May 31, 2023, 6:52am UTC](https://swi-prolog.discourse.group/t/having-trouble-showing-bmp-images-in-xpce-unix-x11/6591 "2023-05-31T06:52:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![faustini1x](https://avatars.discourse-cdn.com/v4/letter/f/0ea827/32.png) [@faustini1x](https://swi-prolog.discourse.group/u/faustini1x)\
**Post date:** [May 31, 2023, 6:52am UTC](https://swi-prolog.discourse.group/t/having-trouble-showing-bmp-images-in-xpce-unix-x11/6591/1 "2023-05-31T06:52:58Z")

</div>

Hello everyone, I’m using: SWI-Prolog version 8.2.4.  
I’m trying to show images in a frame in Prolog, I have read the userguide of XPCE and replicated the code of FileViewer demo. I made some modifications to the code to show an image in a certain window, the code seems to work pretty well when the format of the image is a JPG/JPEG but I want to be able to read also BMP images, is this possible in Unix/X11?  
I have also read that a possible way to solve this is to convert this BMP files to JPG files, but this is not practical for our goals.

My predicate of viewing a file is called view as the same example provided (FileViewer Demo) and looks like this:

```prolog
% your code here
view(DirObj, F) :-
    send(new(V, view(F)), open),
    get(DirObj, file(F), FileObj),
    new(I,image(FileObj)),
    new(Bitmap,bitmap(I)),
    send(V,display,Bitmap).

```

Thanks

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 31, 2023, 8:33am UTC](https://swi-prolog.discourse.group/t/having-trouble-showing-bmp-images-in-xpce-unix-x11/6591/2 "2023-05-31T08:33:27Z")

</div>

This works fine:

```prolog
:- use_module(library(pce)).

view :-
    new(D, directory('/usr/lib/swi-prolog/xpce/prolog/lib/dialog/bitmaps/')),
    view(D, 'slider.bm').

view(DirObj, F) :-
    send(new(V, view(F)), open),
    get(DirObj, file(F), FileObj),
    new(I,image(FileObj)),
    new(Bitmap,bitmap(I)),
    send(V,display,Bitmap).

```

It is a bit odd usage of class view, which is a window showing an editor. Being a window it can display a bitmap on top of of the editor, but whether that is a good idea …

If that doesn’t work, could it be that your file is not a good old X11 bitmap file?

---

<div class="post-metadata">

**Author:** ![faustini1x](https://avatars.discourse-cdn.com/v4/letter/f/0ea827/32.png) [@faustini1x](https://swi-prolog.discourse.group/u/faustini1x)\
**Post date:** [May 31, 2023, 4:06pm UTC](https://swi-prolog.discourse.group/t/having-trouble-showing-bmp-images-in-xpce-unix-x11/6591/3 "2023-05-31T16:06:14Z")

</div>

Ok, the code you provided me works well, however it was my fault to not provide the full idea of what I meant to do. The approach I’m searching with this application is to show images on a window from a directory, the predicate bitmap works perfectly with JPG/JPEG images but not for BMP images. I have tried to search in the documentation another predicate that would let me show a BMP file but I can not find anything.

```prolog
:- use_module(library(pce)).

fileviewer(Dir) :-
    new(DirObj, directory(Dir)),
    new(F, frame('File Viewer')),
    send(F, append(new(B, browser))),
    send(new(D, dialog), below(B)),
    send(D, append(button(view,
        message(@prolog, view,
            DirObj, B?selection?key)))),
    send(D, append(button(quit,
    message(F, destroy)))),
    send(B, members(DirObj?files)),
    send(F, open).

view(DirObj, F) :-
    send(new(V, view(F)), open),
    get(DirObj, file(F), FileObj),
    new(I,image(FileObj)),
    new(Bitmap,bitmap(I)),
    send(V,display,Bitmap).

```

I am truly sorry if my questions are kind of basic but I am just getting started working with XPCE.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [May 31, 2023, 4:51pm UTC](https://swi-prolog.discourse.group/t/having-trouble-showing-bmp-images-in-xpce-unix-x11/6591/4 "2023-05-31T16:51:57Z")

</div>

Sorry, I misread the question

> [@faustini1x](#):
>
> but I want to be able to read also BMP images, is this possible in Unix/X11?

No. It is long ago, but AFAIK we use the Windows functions to read Windows BMP files. These functions are not around on X11/Linux. Best option is probably to use ImageMagic’s convert(1) tool, calling it as something like this.

```
 process_create(path(convert), [file('myfile.bmp'), file('myfile.gif')], [])

```

Of course you could also extend the image import code and send a PR 🙂

Note that xpce is a bit old school. These days it is more popular to write a webserver in SWI-Prolog and use your browser as frontend …

---

<div class="post-metadata">

**Author:** ![faustini1x](https://avatars.discourse-cdn.com/v4/letter/f/0ea827/32.png) [@faustini1x](https://swi-prolog.discourse.group/u/faustini1x)\
**Post date:** [June 2, 2023, 3:28am UTC](https://swi-prolog.discourse.group/t/having-trouble-showing-bmp-images-in-xpce-unix-x11/6591/5 "2023-06-02T03:28:48Z")

</div>

Ok, sorry for answering this late but I was making tests. Changing the BMP image to a GIF works perfectly. I’ll take into account the Web Server, thank you for your support.
