

The full code for this example can be found at \hyperlink{bg_example_02_c}{bg\-\_\-example\-\_\-02.\-c}, in the function {\ttfamily test\-\_\-bg\-\_\-image}. It's part of the {\ttfamily 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\-:


\begin{DoxyCodeInclude}
elm\_main(\textcolor{keywordtype}{int} argc, \textcolor{keywordtype}{char} **argv)
\{
   Evas\_Object *win, *bg;
   \textcolor{keywordtype}{char} buf[PATH\_MAX];

   elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED);
   elm_app_info_set(elm\_main, \textcolor{stringliteral}{"elementary"}, \textcolor{stringliteral}{"images/plant\_01.jpg"});

   win = elm_win_add(NULL, \textcolor{stringliteral}{"bg-image"}, ELM\_WIN\_BASIC);
   elm_win_title_set(win, \textcolor{stringliteral}{"Bg Image"});
   elm_win_autodel_set(win, EINA\_TRUE);

   bg = elm_bg_add(win);

\end{DoxyCodeInclude}


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)\-:


\begin{DoxyCodeInclude}
   elm_bg_load_size_set(bg, 20, 20);

\end{DoxyCodeInclude}


And set our background image to be centered, instead of stretched or scaled, so the effect of the \hyperlink{group__Bg_ga018a212362dea29a77aa1e7c3ee7ef5c}{elm\-\_\-bg\-\_\-load\-\_\-size\-\_\-set()} can be easily understood\-:


\begin{DoxyCodeInclude}
   elm_bg_option_set(bg, ELM_BG_OPTION_CENTER);

\end{DoxyCodeInclude}


We need a filename to set, so we get one from the previous installed images in the {\ttfamily P\-A\-C\-K\-A\-G\-E\-\_\-\-D\-A\-T\-A\-\_\-\-D\-I\-R}, and write its full path to a buffer. Then we use this buffer to set the filename in the background object\-:


\begin{DoxyCodeInclude}
   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"%s/images/plant\_01.jpg"}, elm_app_data_dir_get());
   elm_bg_file_set(bg, buf, NULL);

\end{DoxyCodeInclude}


Notice that the third argument of the \hyperlink{group__Bg_ga621b8c0af0faa3abe3832304e880874e}{elm\-\_\-bg\-\_\-file\-\_\-set()} function is {\ttfamily N\-U\-L\-L}, since we are setting an image to this background. This function also supports setting an edje group as background, in which case the {\ttfamily group} parameter wouldn't be {\ttfamily N\-U\-L\-L}, 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 \hyperlink{bg_01_example_page}{elm\-\_\-bg -\/ Plain color background.} example\-:


\begin{DoxyCodeInclude}
   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();
   elm_shutdown();

   \textcolor{keywordflow}{return} 0;
\}

\end{DoxyCodeInclude}


And this is the end of this example.

This example will look like this\-:

 
\begin{DoxyImage}
\includegraphics{screenshots/bg_01}
\caption{width=}
\end{DoxyImage}
 