Between the Evas examples, there is one in which one creates a canvas bound to the Evas {\bfseries buffer} engine and uses its pixel contents to create an P\+P\+M image on disk.

There, one does that by creating the canvas \char`\"{}by hand\char`\"{}, with {\ttfamily \hyperlink{group__Evas__Canvas_ga67e8eb17d2a676bfdfb8794fc5f72bc0}{evas\+\_\+new()}}, {\ttfamily \hyperlink{group__Evas__Output__Method_ga7244385cf5bad0591ab82e4437c4694b}{evas\+\_\+engine\+\_\+info\+\_\+set()}}, etc.

On this example, we accomplish the very same task, but by using the {\ttfamily Ecore\+\_\+\+Evas} helper wrapper functions on a buffer engine canvas. If you compare both codes, you'll see how much code one is saved from by using the {\ttfamily Ecore\+\_\+\+Evas} wrapper functions.

The code is simple as it can be. After instantianting our canvas window, with \hyperlink{group__Ecore__Evas__Group_gac2e1f186eb493faf7cee9771fb16f49e}{ecore\+\_\+evas\+\_\+buffer\+\_\+new()}, we grab its canvas pointer and create the desired objects scene on it, which in this case is formed by 3 rectangles over the top left corner of a white background\+:  
\begin{DoxyCodeInclude}
main(\textcolor{keywordtype}{void})
\{
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *canvas;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *bg, *r1, *r2, *r3;

   \hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}();

   ee = \hyperlink{group__Ecore__Evas__Group_gac2e1f186eb493faf7cee9771fb16f49e}{ecore\_evas\_buffer\_new}(WIDTH, HEIGHT);
   \textcolor{keywordflow}{if} (!ee) \textcolor{keywordflow}{goto} error;

   canvas = \hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}(ee);

   bg = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(canvas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(bg, 255, 255, 255, 255); \textcolor{comment}{/* white bg */}
   evas\_object\_move(bg, 0, 0); \textcolor{comment}{/* at origin */}
   evas\_object\_resize(bg, WIDTH, HEIGHT); \textcolor{comment}{/* covers full canvas */}
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(bg);

   r1 = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(canvas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(r1, 255, 0, 0, 255); \textcolor{comment}{/* 100% opaque red */}
   evas\_object\_move(r1, 10, 10);
   evas\_object\_resize(r1, 100, 100);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(r1);

   r2 = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(canvas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(r2, 0, 128, 0, 128); \textcolor{comment}{/* 50% opaque green */}
   evas\_object\_move(r2, 10, 10);
   evas\_object\_resize(r2, 50, 50);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(r2);

   r3 = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(canvas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(r3, 0, 128, 0, 255); \textcolor{comment}{/* 100% opaque dark green */}
   evas\_object\_move(r3, 60, 60);
   evas\_object\_resize(r3, 50, 50);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(r3);

\end{DoxyCodeInclude}


Since it's a buffer canvas and we're using it to only save its contents on a file, we even needn't \hyperlink{group__Ecore__Evas__Group_ga4953047ff97d4f1b0d75a7d513d4f317}{ecore\+\_\+evas\+\_\+show()} it. We make it render itself, forcefully, without the aid of Ecore's main loop, with \hyperlink{group__Ecore__Evas__Group_ga93a1c660785fbb2ded46e2bd184e1c04}{ecore\+\_\+evas\+\_\+manual\+\_\+render()}\+:  
\begin{DoxyCodeInclude}
   \hyperlink{group__Ecore__Evas__Group_ga93a1c660785fbb2ded46e2bd184e1c04}{ecore\_evas\_manual\_render}(ee);

\end{DoxyCodeInclude}


And we're ready to save the window's shiny rendered contents as a simple P\+P\+M image. We do so by grabbing the pixels of the {\ttfamily Ecore\+\_\+\+Evas'} internal canvas, with \hyperlink{group__Ecore__Evas__Group_ga32fdb9460318e89beab10cc101d9cf2d}{ecore\+\_\+evas\+\_\+buffer\+\_\+pixels\+\_\+get()}\+:  
\begin{DoxyCodeInclude}
\_scene\_save(\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *canvas,
            \textcolor{keyword}{const} \textcolor{keywordtype}{char} *dest)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} *pixels, *pixels\_end;
   \textcolor{keywordtype}{int} width, height;
   FILE *f;

   \hyperlink{group__Evas__Output__Size_gab2bf31509c58449bc94473f81b1e5ed5}{evas\_output\_size\_get}(canvas, &width, &height);

   f = fopen(dest, \textcolor{stringliteral}{"wb+"});
   \textcolor{keywordflow}{if} (!f)
     \{
        fprintf(stderr, \textcolor{stringliteral}{"ERROR: could not open for writing '%s': %s\(\backslash\)n"},
                dest, strerror(errno));
        \textcolor{keywordflow}{return};
     \}

\end{DoxyCodeInclude}
  
\begin{DoxyCodeInclude}
\textcolor{comment}{/* support function to save scene as PPM image */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_scene\_save(\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *canvas,
            \textcolor{keyword}{const} \textcolor{keywordtype}{char} *dest)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} *pixels, *pixels\_end;
   \textcolor{keywordtype}{int} width, height;
   FILE *f;

   \hyperlink{group__Evas__Output__Size_gab2bf31509c58449bc94473f81b1e5ed5}{evas\_output\_size\_get}(canvas, &width, &height);

   f = fopen(dest, \textcolor{stringliteral}{"wb+"});
   \textcolor{keywordflow}{if} (!f)
     \{
        fprintf(stderr, \textcolor{stringliteral}{"ERROR: could not open for writing '%s': %s\(\backslash\)n"},
                dest, strerror(errno));
        \textcolor{keywordflow}{return};
     \}

   pixels = \hyperlink{group__Ecore__Evas__Group_ga32fdb9460318e89beab10cc101d9cf2d}{ecore\_evas\_buffer\_pixels\_get}(ee);
   pixels\_end = pixels + (width * height);

   \textcolor{comment}{/* PPM P6 format is dead simple to write: */}
   fprintf(f, \textcolor{stringliteral}{"P6\(\backslash\)n%d %d\(\backslash\)n255\(\backslash\)n"}, width, height);
   \textcolor{keywordflow}{for} (; pixels < pixels\_end; pixels++)
     \{
        \textcolor{keywordtype}{int} r, g, b;

        r = ((*pixels) & 0xff0000) >> 16;
        g = ((*pixels) & 0x00ff00) >> 8;
        b = (*pixels) & 0x0000ff;

        fprintf(f, \textcolor{stringliteral}{"%c%c%c"}, r, g, b);
     \}

   fclose(f);
   printf(\textcolor{stringliteral}{"Saved scene as '%s'\(\backslash\)n"}, dest);
\}

\end{DoxyCodeInclude}


Check that destination file for the result. The full example follows.


\begin{DoxyCodeInclude}

\textcolor{preprocessor}{#ifdef HAVE\_CONFIG\_H}

\textcolor{preprocessor}{#include "config.h"}
\textcolor{preprocessor}{#else}
\textcolor{preprocessor}{#define EINA\_UNUSED}
\textcolor{preprocessor}{#endif}

\textcolor{preprocessor}{#include <\hyperlink{Ecore__Evas_8h}{Ecore\_Evas.h}>}
\textcolor{preprocessor}{#include <stdio.h>}

\textcolor{preprocessor}{#define WIDTH  (320)}
\textcolor{preprocessor}{#define HEIGHT (240)}

\textcolor{keyword}{static} Ecore\_Evas *ee;

\textcolor{comment}{/* support function to save scene as PPM image */}
\textcolor{keyword}{static} \textcolor{keywordtype}{void}
\_scene\_save(\hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *canvas,
            \textcolor{keyword}{const} \textcolor{keywordtype}{char} *dest)
\{
   \textcolor{keyword}{const} \textcolor{keywordtype}{unsigned} \textcolor{keywordtype}{int} *pixels, *pixels\_end;
   \textcolor{keywordtype}{int} width, height;
   FILE *f;

   \hyperlink{group__Evas__Output__Size_gab2bf31509c58449bc94473f81b1e5ed5}{evas\_output\_size\_get}(canvas, &width, &height);

   f = fopen(dest, \textcolor{stringliteral}{"wb+"});
   \textcolor{keywordflow}{if} (!f)
     \{
        fprintf(stderr, \textcolor{stringliteral}{"ERROR: could not open for writing '%s': %s\(\backslash\)n"},
                dest, strerror(errno));
        \textcolor{keywordflow}{return};
     \}

   pixels = \hyperlink{group__Ecore__Evas__Group_ga32fdb9460318e89beab10cc101d9cf2d}{ecore\_evas\_buffer\_pixels\_get}(ee);
   pixels\_end = pixels + (width * height);

   \textcolor{comment}{/* PPM P6 format is dead simple to write: */}
   fprintf(f, \textcolor{stringliteral}{"P6\(\backslash\)n%d %d\(\backslash\)n255\(\backslash\)n"}, width, height);
   \textcolor{keywordflow}{for} (; pixels < pixels\_end; pixels++)
     \{
        \textcolor{keywordtype}{int} r, g, b;

        r = ((*pixels) & 0xff0000) >> 16;
        g = ((*pixels) & 0x00ff00) >> 8;
        b = (*pixels) & 0x0000ff;

        fprintf(f, \textcolor{stringliteral}{"%c%c%c"}, r, g, b);
     \}

   fclose(f);
   printf(\textcolor{stringliteral}{"Saved scene as '%s'\(\backslash\)n"}, dest);
\}

\textcolor{keywordtype}{int}
main(\textcolor{keywordtype}{void})
\{
   \hyperlink{group__Evas__Canvas_ga5ff87cc4ce6bc43e3b640a6d37f73043}{Evas} *canvas;
   \hyperlink{group__Evas__Object__Group_ga9e19e6dd1f517a0ba437c0114d3e7c97}{Evas\_Object} *bg, *r1, *r2, *r3;

   \hyperlink{group__Ecore__Evas__Group_ga32ddbb6457033ad435a177eb0c4fe235}{ecore\_evas\_init}();

   ee = \hyperlink{group__Ecore__Evas__Group_gac2e1f186eb493faf7cee9771fb16f49e}{ecore\_evas\_buffer\_new}(WIDTH, HEIGHT);
   \textcolor{keywordflow}{if} (!ee) \textcolor{keywordflow}{goto} error;

   canvas = \hyperlink{group__Ecore__Evas__Group_ga75a7cc694b6069e78df47dab0b0f2d20}{ecore\_evas\_get}(ee);

   bg = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(canvas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(bg, 255, 255, 255, 255); \textcolor{comment}{/* white bg */}
   evas\_object\_move(bg, 0, 0); \textcolor{comment}{/* at origin */}
   evas\_object\_resize(bg, WIDTH, HEIGHT); \textcolor{comment}{/* covers full canvas */}
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(bg);

   r1 = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(canvas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(r1, 255, 0, 0, 255); \textcolor{comment}{/* 100% opaque red */}
   evas\_object\_move(r1, 10, 10);
   evas\_object\_resize(r1, 100, 100);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(r1);

   r2 = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(canvas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(r2, 0, 128, 0, 128); \textcolor{comment}{/* 50% opaque green */}
   evas\_object\_move(r2, 10, 10);
   evas\_object\_resize(r2, 50, 50);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(r2);

   r3 = \hyperlink{group__Evas__Object__Rectangle_ga4d80fc32ad1cac28428cebd65d746751}{evas\_object\_rectangle\_add}(canvas);
   \hyperlink{group__Evas__Object__Group__Basic_gae34bdcfd7f5100151f6ea8ef4a392949}{evas\_object\_color\_set}(r3, 0, 128, 0, 255); \textcolor{comment}{/* 100% opaque dark green */}
   evas\_object\_move(r3, 60, 60);
   evas\_object\_resize(r3, 50, 50);
   \hyperlink{group__Evas__Object__Group__Basic_ga9cbc13661584e49fb9d9cdab514a1eeb}{evas\_object\_show}(r3);

   \hyperlink{group__Ecore__Evas__Group_ga93a1c660785fbb2ded46e2bd184e1c04}{ecore\_evas\_manual\_render}(ee);
   \_scene\_save(canvas, \textcolor{stringliteral}{"/tmp/evas-buffer-simple-render.ppm"});

   \hyperlink{group__Ecore__Evas__Group_gad3ec61f2aa03df4d3dbfd0d311e0c8dc}{ecore\_evas\_free}(ee);
   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();

   \textcolor{keywordflow}{return} 0;

error:
   fprintf(stderr, \textcolor{stringliteral}{"You got to have at least one Evas engine built"}
                   \textcolor{stringliteral}{" and linked up to ecore-evas for this example to run"}
                   \textcolor{stringliteral}{" properly.\(\backslash\)n"});
   \hyperlink{group__Ecore__Evas__Group_gab8fa311077f749190c9b622f672b2214}{ecore\_evas\_shutdown}();
   \textcolor{keywordflow}{return} -1;
\}

\end{DoxyCodeInclude}
 