Skip navigation.
Home
The QNX Community Portal

View topic - load and display an image using libimg and Screen API

load and display an image using libimg and Screen API

Isn't the name clear?

load and display an image using libimg and Screen API

Postby lilazheng » Mon May 05, 2014 5:04 pm

Hi,

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 http://support7.qnx.com/download/downlo ... _Guide.pdf, also the sample code given in the post https://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];
free(screen_disps);

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;

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

}

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

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.

Lila
lilazheng
New Member
 
Posts: 1
Joined: Wed Apr 23, 2014 2:44 pm

Re: load and display an image using libimg and Screen API

Postby Tim » Wed May 07, 2014 8:27 pm

Lila

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

Here is an example of using img_load_file()

http://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.

Tim
Tim
Senior Member
 
Posts: 1392
Joined: Wed Mar 10, 2004 12:28 am


Return to GUI Programming

Who is online

Users browsing this forum: No registered users and 0 guests