Use Screen with the Camera API

If you want to show video on your display, you need to use the Screen Graphics Subsystem (Screen).

Screen is required to show the image buffer on the display. This requires that you use window buffers from Screen to handle image buffers from the Camera API. For this reason, you'll need set up Screen in your application. As part of the setup to connect Screen with the Camera API, you must create a Screen Group ID. Then, you call camera_set_vf_property() to pass the handle to the camera, the Group ID, and Window ID. Ensure that when you create a window group that you call screen_flush_context() because it's a queued operation. For more information, see the Screen Developer's Guide. From here, the Sensor service takes care of ensuring that the image buffers are sent to Screen.

We provide a few examples of how to use Screen with the Camera Library. For more detailed information about to use Screen, see the Screen Developer's Guide.

To set up Screen, you must do the following: Here's a code snippet of what your code can look like:
...
...
screen_context_t screenContext = NULL;
screen_window_t appWindow = NULL;
screen_window_t viewfinderWindow = NULL;
screen_buffer_t screenBuffer;

int screenUsage = SCREEN_USAGE_NATIVE;
int screenFormat = SCREEN_FORMAT_RGBA8888;
// For the group ID
char groupId[64];

// variables to fill the window with blue
int size[2];
int blitInfo[] = {SCREEN_BLIT_COLOR, (int) 0xff0000ff, SCREEN_BLIT_END};

// Create the context and a window
screen_create_context(screenContext, 0);
screen_create_window(window, *context)

//Set properties for the window
screen_set_window_property_iv(*window, SCREEN_PROPERTY_USAGE, &screenUsage);
screen_set_window_property_iv(*window, SCREEN_PROPERTY_FORMAT, &screenFormat);



// Put something default to ensure that the window shows it,
//         such as a blue startup screen:
screen_get_window_property_pv(appWIndow, SCREEN_PROPERTY_RENDER_BUFFERS,
                                         (void **)&screenBuffer);
screen_get_window_property_iv(appWIndow, SCREEN_PROPERTY_BUFFER_SIZE, size);

// Blit blue color to the window
screen_fill(context, screenBuffer, blitInfo);

// Get size of the window
screen_get_window_property_iv(window, SCREEN_PROPERTY_BUFFER_SIZE, size);
int rects[4] = {0};
rects[2] = size[0];
rects[3] = size[1];
screen_post_window(window, screenBuffer, 1, rects, 0);

// Create a window group and retrieve it. 
// Screen creates a unique group ID for you when
// you pass NULL to it (recommended).
screen_create_window_group(appWindow, NULL);
screen_get_window_property_cv(appWindow, SCREEN_PROPERTY_GROUP, 64, groupId);

// Then you must flush the context since creating a window group
// is a queue operation
(screen_flush_context(*context, SCREEN_WAIT_IDLE);
                   
//Start the imaging datapath
camera_set_vf_property(handle, CAMERA_IMGPROP_WIN_GROUPID, groupId,
                               CAMERA_IMGPROP_WIN_ID, windowId);
...
...