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


Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.


Reply
New Developer
Posts: 6
Registered: ‎03-26-2012
My Device: PLaybook 16GB
My Carrier: Rogers

Reading image from file and displaying it

Hi All,

 

Can someone provide few lines of code showing the usage of img_t structure to read from file, using img_load_file, and display it on device. The critical part would be assignig the pointer to direct.data.

 

Thanks,

Dan

New Contributor
Posts: 6
Registered: ‎03-12-2012
My Device: Non
My Carrier: Non

Re: Reading image from file and displaying it

[ Edited ]

Hello there,

 

It has been alot of pain for me to do that (as in I had trouble with loading images until I figured it out). Everything is available in the Gesture sample app. Here is the code below:

 

//-----------------------Load Image---------------------------

static int decode_setup(uintptr_t data, img_t *img, unsigned flags)
{
    screen_window_t bg_win = (screen_window_t)data;
    screen_buffer_t screen_buf;
    int Fsize[2];

    Fsize[0] = img->w;
    Fsize[1] = img->h;
    screen_set_window_property_iv(bg_win, SCREEN_PROPERTY_BUFFER_SIZE, Fsize);
    screen_create_window_buffers(bg_win, 1);

    screen_get_window_property_pv(bg_win, SCREEN_PROPERTY_RENDER_BUFFERS, (void **)&bg_buf);
    screen_get_buffer_property_pv(bg_buf, SCREEN_PROPERTY_POINTER, (void **)&img->access.direct.data);
    screen_get_buffer_property_iv(bg_buf, SCREEN_PROPERTY_STRIDE, (int *)&img->access.direct.stride);

    img->flags |= IMG_DIRECT;
    return IMG_ERR_OK;
}

static void decode_abort(uintptr_t data, img_t *img)
{
    screen_window_t bg_win = (screen_window_t)data;
    screen_destroy_window_buffers(bg_win);
}

int
load_image(screen_window_t bg_win, const char *path)
{
    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;
    }

    img.flags = 0;

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

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

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

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

//-----------------------Load Image---------------------------

 

Just change bg_win and bg_buf with your variables. To load, just use the load_image function with you window name and the path. The path is of the following format: 

 

const char* path = "app/native/_____.jpg"; /* Relative path to image asset */

 

Make sure the image is an asset.

 

Good luck Smiley Happy