

This example is as simple as possible. An image object will be added to the window over a white background, and set to be resizable together with the window. All the options set through the example will affect the behavior of this image.

We start with the code for creating a window and its background, and also add the code to write the path to the image that will be loaded\+:


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

   elm_app_info_set(elm\_main, \textcolor{stringliteral}{"elementary"}, \textcolor{stringliteral}{"images/plant\_01.jpg"});
   elm_policy_set(ELM\_POLICY\_QUIT, ELM\_POLICY\_QUIT\_LAST\_WINDOW\_CLOSED);

   win = elm_win_util_standard_add(\textcolor{stringliteral}{"image"}, \textcolor{stringliteral}{"Image"});
   elm_win_autodel_set(win, EINA\_TRUE);

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

\end{DoxyCodeInclude}


Now we create the image object, and set that file to be loaded\+:


\begin{DoxyCodeInclude}

   image = elm_image_add(win);
   \textcolor{keywordflow}{if} (!elm_image_file_set(image, buf, NULL))
     \{
        printf(\textcolor{stringliteral}{"error: could not load image \(\backslash\)"%s\(\backslash\)"\(\backslash\)n"}, buf);
        \textcolor{keywordflow}{return} -1;
     \}

\end{DoxyCodeInclude}


We can now go setting our options.

\hyperlink{group__Elm__Image_gad5e7c1a774e7ef991e8f7726e4aee23b}{elm\+\_\+image\+\_\+no\+\_\+scale\+\_\+set()} is used just to set this value to true (we don\textquotesingle{}t want to scale our image anyway, just resize it).

\hyperlink{group__Elm__Image_ga4ee58d06eb76efaf8996c7eb86469119}{elm\+\_\+image\+\_\+resizable\+\_\+set()} is used to allow the image to be resized to a size smaller than the original one, but not to a size bigger than it.

\hyperlink{group__Elm__Image_gad1616cb527a0110058cb45b5e8307cd7}{elm\+\_\+image\+\_\+smooth\+\_\+set()} will disable the smooth scaling, so the scale algorithm used to scale the image to the new object size is going to be faster, but with a lower quality.

\hyperlink{group__Elm__Image_ga08ea6d0c413dcfe64a877899e0d3e466}{elm\+\_\+image\+\_\+orient\+\_\+set()} is used to flip the image around the (1, 0) (0, 1) diagonal.

\hyperlink{group__Elm__Image_ga33716e03738241f4ca4129fdf745ae45}{elm\+\_\+image\+\_\+aspect\+\_\+fixed\+\_\+set()} is used to keep the original aspect ratio of the image, even when the window is resized to another aspect ratio.

\hyperlink{group__Elm__Image_ga962c104caf9ad23f21627a433af4a71a}{elm\+\_\+image\+\_\+fill\+\_\+outside\+\_\+set()} is used to ensure that the image will fill the entire area available to it, even if keeping the aspect ratio. The image will overflow its width or height (any of them that is necessary) to the object area, instead of resizing the image down until it can fit entirely in this area.

\hyperlink{group__Elm__Image_ga24230da3c83aa5139aa2f6a1545f8bf3}{elm\+\_\+image\+\_\+editable\+\_\+set()} is used just to cover the A\+PI, but won\textquotesingle{}t affect this example since we are not using any copy \& paste property.

This is the code for setting these options\+:


\begin{DoxyCodeInclude}

   elm_image_no_scale_set(image, EINA\_TRUE);
   elm_image_resizable_set(image, EINA\_FALSE, EINA\_TRUE);
   elm_image_smooth_set(image, EINA\_FALSE);
   elm_image_orient_set(image, ELM\_IMAGE\_FLIP\_HORIZONTAL);
   elm_image_aspect_fixed_set(image, EINA\_TRUE);
   elm_image_fill_outside_set(image, EINA\_TRUE);
   elm_image_editable_set(image, EINA\_TRUE);

\end{DoxyCodeInclude}


Now some last touches in our object size hints, window and background, to display this image properly\+:


\begin{DoxyCodeInclude}

   evas\_object\_size\_hint\_weight\_set(image, EVAS\_HINT\_EXPAND, EVAS\_HINT\_EXPAND);
   elm_win_resize_object_add(win, image);
   evas\_object\_show(image);

   evas\_object\_resize(win, 320, 320);
   evas\_object\_show(win);

   elm_run();

   \textcolor{keywordflow}{return} 0;
\}
ELM_MAIN()

\end{DoxyCodeInclude}


This example will look like this\+:

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