Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Help on loading and displaying jpg/png with NDK

you can find these pieces of code in samples, this works for me:

img_decode_callouts_t Callouts;
img_lib_t ilib = NULL;
img_t img;
char strFileName[]= "yourfilename";
int rc = img_lib_attach(&ilib);
memset(&img, 0, sizeof(img));
memset(&Callouts, 0, sizeof(Callouts));
rc = img_load_file(ilib, strFileName, NULL, &img);
img_lib_detach(ilib);

/* your window should be initialized already*/

_uint8 *ScreenData;
screen_buffer_t screen_buf;	
screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf);
screen_get_buffer_property_pv(screen_buf, SCREEN_PROPERTY_POINTER, (void **)&ScreenData);
for (unsigned int y=0; y < img.h; y++){
  memcpy(ScreenData + y*nScreenWidth*nBytesPerPixel, img.access.direct.data + y*img.direct.stride, img.access.direct.stride);
}
int rect[4] = { 0, 0, img.w, img.h };
screen_post_window(screen_win, screen_buf, 1, rect, 0);

 

Highlighted
Developer
Posts: 1,636
Registered: ‎07-14-2008
My Device: Z10
My Carrier: Fido

Re: Help on loading and displaying jpg/png with NDK


BGmot wrote:

you can find these pieces of code in samples, this works for me:

img_decode_callouts_t Callouts;
img_lib_t ilib = NULL;
img_t img;
char strFileName[]= "yourfilename";
int rc = img_lib_attach(&ilib);
memset(&img, 0, sizeof(img));
memset(&Callouts, 0, sizeof(Callouts));
rc = img_load_file(ilib, strFileName, NULL, &img);
img_lib_detach(ilib);

/* your window should be initialized already*/

_uint8 *ScreenData;
screen_buffer_t screen_buf;	
screen_get_window_property_pv(screen_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&screen_buf);
screen_get_buffer_property_pv(screen_buf, SCREEN_PROPERTY_POINTER, (void **)&ScreenData);
for (unsigned int y=0; y < img.h; y++){
  memcpy(ScreenData + y*nScreenWidth*nBytesPerPixel, img.access.direct.data + y*img.direct.stride, img.access.direct.stride);
}
int rect[4] = { 0, 0, img.w, img.h };
screen_post_window(screen_win, screen_buf, 1, rect, 0);

 


thanks will give it a go.

New Contributor
Posts: 3
Registered: ‎02-18-2013
My Device: BlackBerry PlayBook
My Carrier: Vodafone

Re: Help on loading and displaying jpg/png with NDK

Hello, my name is Joe and am currently work on my 4th year project, i having difficulties with loading multiple images, resizing them and position the on areas on the playbook screen, and how i could use the image as a button, could to please help me out . thank very much

Developer
Posts: 1,068
Registered: ‎11-24-2011
My Device: PlayBook
My Carrier: x

Re: Help on loading and displaying jpg/png with NDK

- loading images

- resizing them

- position them on areas

are three different tasks. Which one(s) are you having difficulties with? What approach are you taking and what is failing?

New Contributor
Posts: 3
Registered: ‎02-18-2013
My Device: BlackBerry PlayBook
My Carrier: Vodafone

Re: Help on loading and displaying jpg/png with NDK

[ Edited ]

Thanks, i was able load an image, 

i want to be able to load multiple images (png)

 

and i cant resize the image and position them 

so i have problem with mainly 2 and 3 listed.

 

The approach i take was to use the load_image_resize_fiile()

here is the code i have

 

int load_image(screen_window_t screen_win, const char *path, int x, int y)
{
img_decode_callouts_t callouts;
img_lib_t ilib = NULL;
img_t img;
int rc;

rc = img_lib_attach(&ilib);
if (rc != IMG_ERR_OK) {
return -1;
}

memset(&img, 0, sizeof(img_t));
img.flags |= IMG_FORMAT;
img.format = IMG_FMT_PKLE_XRGB8888;


memset(&callouts, 0, sizeof(callouts));
callouts.setup_f = decode_setup;
callouts.abort_f = decode_abort;
callouts.data = (uintptr_t)screen_win;

 

img.flags |= IMG_RESIZE;

img.w = x;
img.flags |= IMG_W;

img.h = y;
img.flags |= IMG_H;

 

rc = img_load_resize_file(ilib, path, &callouts, &img);

 

img.flags |= IMG_DIRECT;


img_lib_detach(ilib);


return rc == IMG_ERR_OK ? 0 : -1;
}

 

thanks very much