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:
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):
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:
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:
And this is the end of this example.
This example will look like this: