

The full code for this example can be found at \mbox{\hyperlink{bg_example_02_c}{bg\+\_\+example\+\_\+02.\+c}}, in the function {\ttfamily test\+\_\+bg\+\_\+image}. It\textquotesingle{}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}{0}
\DoxyCodeLine{elm\_main(\textcolor{keywordtype}{int} argc \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}}, \textcolor{keywordtype}{char} **argv \mbox{\hyperlink{group__Eina__Types__Group_ga82d751be730f849719ca292f9558be87}{EINA\_UNUSED}})}
\DoxyCodeLine{\{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object}} *win, *bg;}
\DoxyCodeLine{   \textcolor{keywordtype}{char} buf[PATH\_MAX];}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_ga7a05f37fd3a019da5e26c5fc91fcd937}{elm\_policy\_set}}(\mbox{\hyperlink{group__Elm__General_ggaa16f3378ecdbf660fa378402e3c5a0a9a02fadb6faada04b19d0fa42c11a8d32a}{ELM\_POLICY\_QUIT}}, \mbox{\hyperlink{group__Elm__General_gga46af37e6ac2c406321060be827117196abbe0962d88ae12afe1a173da881f56cd}{ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__App_ga0cefb59efb95841232561d67e34d9909}{elm\_app\_info\_set}}(elm\_main, \textcolor{stringliteral}{"elementary"}, \textcolor{stringliteral}{"images/plant\_01.jpg"});}
\DoxyCodeLine{}
\DoxyCodeLine{   win = \mbox{\hyperlink{group__Elm__Win_gad127cc5ae04689c4f2c5b633056d0ac8}{elm\_win\_add}}(NULL, \textcolor{stringliteral}{"bg-\/image"}, \mbox{\hyperlink{group__Elm__Win_gga4df03d1a1e94e8b24a58d8ccc5d4d514a505928a16effb6fff3caa009a7d306b7}{ELM\_WIN\_BASIC}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Win_ga0e0b613ac6b5d1e0e71f2ec17e80cb07}{elm\_win\_title\_set}}(win, \textcolor{stringliteral}{"Bg Image"});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Win_ga9a16a2f8c9fd5b6e9203ed9dcb53ea8b}{elm\_win\_autodel\_set}}(win, \mbox{\hyperlink{group__Eina__Types__Group_ga05c12dacc8b4058994df842b41be85fc}{EINA\_TRUE}});}
\DoxyCodeLine{}
\DoxyCodeLine{   bg = \mbox{\hyperlink{group__Elm__Bg_gaeec8f79ac62ce0cf607cfe330008a63f}{elm\_bg\_add}}(win);}

\end{DoxyCodeInclude}


Now it\textquotesingle{}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\textquotesingle{}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\textquotesingle{}s just a hint)\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Bg_ga6aef5e17ed70d3391401f0395fda06e9}{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 \mbox{\hyperlink{group__Elm__Bg_ga6aef5e17ed70d3391401f0395fda06e9}{elm\+\_\+bg\+\_\+load\+\_\+size\+\_\+set()}} can be easily understood\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Bg_ga2ed059b3cf946d10a12182fedc3125f9}{elm\_bg\_option\_set}}(bg, \mbox{\hyperlink{group__Elm__Bg_ggac13a24993e39fac3484bd29a9bfeea26a59df3d0f575cd2bc133c367beca423dc}{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\+IR}, and write its full path to a buffer. Then we use this buffer to set the filename in the background object\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   snprintf(buf, \textcolor{keyword}{sizeof}(buf), \textcolor{stringliteral}{"\%s/images/plant\_01.jpg"}, \mbox{\hyperlink{group__Elm__App_ga92a09dbf88cc1ca3eab51c51dea589d0}{elm\_app\_data\_dir\_get}}());}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Bg_ga0b11c11879de61126414adfbfe3e431c}{elm\_bg\_file\_set}}(bg, buf, NULL);}

\end{DoxyCodeInclude}


Notice that the third argument of the \mbox{\hyperlink{group__Elm__Bg_ga0b11c11879de61126414adfbfe3e431c}{elm\+\_\+bg\+\_\+file\+\_\+set()}} function is {\ttfamily N\+U\+LL}, 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\textquotesingle{}t be {\ttfamily N\+U\+LL}, 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 \mbox{\hyperlink{bg_01_example_page}{elm\+\_\+bg -\/ Plain color background.}} example\+:


\begin{DoxyCodeInclude}{0}
\DoxyCodeLine{   evas\_object\_size\_hint\_weight\_set(bg, \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}}, \mbox{\hyperlink{Evas__Common_8h_aa47c85083d3dae0111c21ec49359306a}{EVAS\_HINT\_EXPAND}});}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__Win_ga505d6bd217e5ee01e82b548ec35986eb}{elm\_win\_resize\_object\_add}}(win, bg);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(bg);}
\DoxyCodeLine{}
\DoxyCodeLine{   evas\_object\_resize(win, 320, 320);}
\DoxyCodeLine{   \mbox{\hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}}(win);}
\DoxyCodeLine{}
\DoxyCodeLine{   \mbox{\hyperlink{group__Elm__General_gadf2553f83e6b0b9c7fbe054019a664a1}{elm\_run}}();}
\DoxyCodeLine{}
\DoxyCodeLine{   \textcolor{keywordflow}{return} 0;}
\DoxyCodeLine{\}}

\end{DoxyCodeInclude}


And this is the end of this example.

This example will look like this\+:

 
\begin{DoxyImageNoCaption}
  \mbox{\includegraphics[width=\textwidth]{screenshots/bg_01}}
\end{DoxyImageNoCaption}
 