a. Screen Capture To File

<< Click to Display Table of Contents >>

Navigation:  Tutorials > Tutorial 10 - Screen Control >

a. Screen Capture To File

This section shows how to take a screenshot and save it to a file using the CaptureScreen() command.

 

 

Command Prototype

 

uint16_t CaptureScreen(const char* FileName, int X, int Y, int Width, int Height)

 

Parameters

Description

FileName

refers to the absolute file path of the saved image

X Y

start point coordinates

Width

area width to be captured

Height

area height to be captured

 

 

Code

 

 

void setup()

{

/* Initialize CleO - needs to be done only once */

 CleO.begin();

 

 /* Start building a screen frame */

 CleO.Start();

 

/* Draw a sample image */

 CleO.SetBackgroundcolor(DARK_BLUE);

 CleO.CircleExt(60, 60, 10, 20, DARKORANGE3, MM, 0, 0);

 CleO.CircleExt(60, 60, 30, 40, DARKORANGE2, MM, 0, 0);

 CleO.CircleExt(60, 60, 50, 60, DARKORANGE1, MM, 0, 0);

 CleO.StringExt(FONT_MEDIUM, 60, 60, WHITE, MM, 0, 0, "CleO");

 

 /* Display completed screen frame */

 CleO.Show();

 

/* Capture screen starting from (0,0) and with 120 width and height.  */

 CleO.CaptureScreen("@Pictures/screenshot.png", 0, 0, 120, 120);

 

/* Get the handle of saved screen shot file */

 h0 = CleO.LoadImageFile("@Pictures/screenshot.png", 0);

 

/* Fill up the entire screen with captured screen-shot */

 CleO.Start();

 CleO.BitmapJustification(MM);

 for (int x = 0; x < 320 + 60; x += 120)

   for (int y = 0; y < 480 + 60; y += 120)

     CleO.Bitmap(h0, x, y);

 CleO.Show();

 

/* Capture the final screen-shot */

 CleO.CaptureScreen("@Pictures/capturescreen.png", 0, 0, 320, 480);

}

 

void loop() {}

 

 

Description

 

The first part of above code snippet creates an image with circle using the CircleExt() command and draws it on the screen using the Show()routine. The image is captured on the screen using the CaptureScreen() command and saves the captured area (0,0) to (120,120) to "screenshot.png" file. The second part of the code loads the "screenshot.png" file using the LoadImageFile() command and draws it multiple times in the for loop using the Bitmap() command. Finally, the whole screen is captured filled with this image. The entire screen is obtained from (0,0) to  (320,480).

 

Use the @ symbol only when performing the file operation from the eFlash and not from the SD Card.

 

 

Output

 

Here is the output displayed upon executing the above code snippet -

 

capturescreen