load and display an image using libimg and Screen API


I am a beginner in leaning QNX. I just have an assignment to load and display an image using the image library “libimg” and the “QNX Screen” API.

I created my code based on the sample code given in github.com/blackberry/NDK-Sampl … ure/main.c. My code is below (omit all print code for debugging):

static img_t img;
screen_context_t screen_context;
screen_window_t screen_window;

int main(int argc, char * const argv[]) {
screen_create_context(&screen_context, SCREEN_APPLICATION_CONTEXT);
screen_create_window(&screen_window, screen_context);

int count = 0;
screen_get_context_property_iv(screen_context,SCREEN_PROPERTY_DISPLAY_COUNT, &count);
screen_display_t *screen_disps = calloc(count, sizeof(screen_display_t));
screen_get_context_property_pv(screen_context, SCREEN_PROPERTY_DISPLAYS,	(void **) screen_disps);
screen_display_t screen_disp = screen_disps[0];

int vis = 1;
int dims[2] = { 512, 512 };
int rect[4] = { 0, 0, 1, 1 };
screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_VISIBLE, &vis);
screen_set_window_property_iv(screen_window, SCREEN_PROPERTY_BUFFER_SIZE,rect + 2);
rev = screen_set_window_property_iv(screen_window,SCREEN_PROPERTY_SOURCE_SIZE, dims);

screen_buffer_t screen_buf;
screen_create_window_buffers(screen_window, 1);
screen_get_window_property_pv(screen_window, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf);

screen_get_buffer_property_pv(screen_buf, SCREEN_PROPERTY_POINTER, (void **)&img.access.direct.data);
screen_get_buffer_property_iv(screen_buf, SCREEN_PROPERTY_STRIDE, (int *)&img.access.direct.stride);
img.flags |= IMG_DIRECT;

screen_post_window(screen_window, screen_buf, 1, rect, 0);


static void loadImg(void) {
img_lib_t ilib = NULL;
int rc1 = 0;
img.w = 512;
img.flags |= IMG_W;
img.h = 512;
img.flags |= IMG_H;
rc1 == img_load_file(ilib,filename , NULL, &img);

The debug info shows that loading image is successful, however what I can see is a 512*512 white image in my screen. I don’t know where is the problem, hope I can get some help here.

Thank you very much.



I am not sure you can display your image in screen window.

Here is an example of using img_load_file()

himmele.googlecode.com/svn/trunk … icsTest.cc

You might be able to just copy this and replace his 5 sample images with just your 1 image.