Tizen Native API  5.5
elm_bg - Image background.

The full code for this example can be found at bg_example_02.c, in the function test_bg_image. It's part of the elementary_test suite, and thus has the code for the three examples referenced by this documentation.

This is the second example, and shows how to use the Elementary background object to set an image as background of your application.

We start this example exactly in the same way as the previous one, even when creating the background object:

elm_main(int argc EINA_UNUSED, char **argv EINA_UNUSED)
{
   Evas_Object *win, *bg;
   char buf[PATH_MAX];

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
   elm_app_info_set(elm_main, "elementary", "images/plant_01.jpg");

   win = elm_win_add(NULL, "bg-image", ELM_WIN_BASIC);
   elm_win_title_set(win, "Bg Image");
   elm_win_autodel_set(win, EINA_TRUE);

   bg = elm_bg_add(win);

Now it's the different part.

Our background will have an image, that will be displayed over the background color. Before loading the image, we set the load size of the image. The load size is a hint about the size that we want the image displayed in the screen. It's not the exact size that the image will have, but usually a bit bigger. The background object can still be scaled to a size bigger than the one set here. Setting the image load size to something smaller than its real size will reduce the memory used to keep the pixmap representation of the image, and the time to load it. Here we set the load size to 20x20 pixels, but the image is loaded with a size bigger than that (since it's just a hint):

   elm_bg_load_size_set(bg, 20, 20);

And set our background image to be centered, instead of stretched or scaled, so the effect of the elm_bg_load_size_set() can be easily understood:

We need a filename to set, so we get one from the previous installed images in the PACKAGE_DATA_DIR, and write its full path to a buffer. Then we use this buffer to set the filename in the background object:

   snprintf(buf, sizeof(buf), "%s/images/plant_01.jpg", elm_app_data_dir_get());
   elm_bg_file_set(bg, buf, NULL);

Notice that the third argument of the elm_bg_file_set() function is NULL, since we are setting an image to this background. This function also supports setting an edje group as background, in which case the group parameter wouldn't be NULL, but be the name of the group instead.

Finally, we can set the size hints, add the background as a resize object, and resize the window, exactly the same thing we do in the elm_bg - Plain color background. example:

   evas_object_size_hint_weight_set(bg, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(win, bg);
   evas_object_show(bg);

   evas_object_resize(win, 320, 320);
   evas_object_show(win);

   elm_run();

   return 0;
}

And this is the end of this example.