Languages

Menu
Sites
Language
Backgroung app from file

Hello everybody!

I am trying to set a image as a background, I wrote this code, win is the window container, the file exists, even tryed with png format, is not showing nothing, any one knows what I am doing wrong?

Thanks to all!

Evas_Object *bg;

elm_bg_file_set(bg, "/opt/usr/media/bg.jpg", NULL);
elm_bg_option_set(bg, ELM_BG_OPTION_STRETCH);
bg = elm_bg_add(ad->win);
//evas_object_show(bg); // I think is not needed

View Selected Answer

Responses

3 Replies
Carlos Dominguez

And also tried to do this:

Evas_Object *bg;

bg = elm_bg_add(ad->win);

elm_bg_file_set(bg, "/opt/usr/media/bg.jpg", NULL);
elm_bg_option_set(bg, ELM_BG_OPTION_STRETCH);
 

No luck!

Mark as answer
Mango Bar

Use a container to show your image and put your image in res folder. Have look on following code where i put my image in  table container.

My image location is res/images/img.png

    /* Table Container*/

    Evas_Object *table = elm_table_add(ad->win);
    elm_table_homogeneous_set(table, EINA_TRUE);
    evas_object_size_hint_weight_set(table, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
    elm_win_resize_object_add(ad->win, table);
    evas_object_show(table);

    Evas_Object *bg;

   /* Image path */

    char buf[PATH_MAX];
    app_get_resource("images/img.png", buf, (int)PATH_MAX);

   /* Image */

   bg = elm_bg_add(ad->win);
   elm_bg_option_set(bg, ELM_BG_OPTION_STRETCH);
   elm_bg_file_set(bg, buf, NULL);
   my_table_pack(table, bg, 0, 2, 2, 2);

 

Here app_get_resource  is a custom function which is used to get file path from res folder

static void app_get_resource(const char *res_file_in, char *res_path_out, int res_path_max)
{
    char *res_path = app_get_resource_path();
    if (res_path) {
        snprintf(res_path_out, res_path_max, "%s%s", res_path, res_file_in);
        free(res_path);
    }
}

my_table_pack is also a custom function which is used to put image in table container.

static void my_table_pack(Evas_Object *table, Evas_Object *child, int x, int y, int w, int h)
{
   evas_object_size_hint_align_set(child, EVAS_HINT_FILL, EVAS_HINT_FILL);
   evas_object_size_hint_weight_set(child, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_table_pack(table, child, x, y, w, h);
   evas_object_show(child);
}

 

Carlos Dominguez

Thanks another time Mango!