This library allows you to take screenshots of a 16-bit RGB565 LGFX_Sprite or LGFX_Device display and save these as 24-bit RGB888 BMP files on a mounted filesystem.
I wrote this library because the RGB565 format is almost unsupported on pc.
Designed for ESP32 devices using LovyanGFX.
Psram and LovyanGFX are required to run this library.
Currently the library only accepts RGB565 sources.
- Saves 16-bit RGB565 sources as 24-bit RGB888
- Supports both LGFX_Sprite and LGFX_Device sources
- ESP32 (any variant with psram)
- LovyanGFX
- A mounted filesystem
#include <Arduino.h>
#include <SD.h>
#include <LovyanGFX.h>
#include <LGFX_AUTODETECT.hpp>
#include <ScreenShot.hpp>
constexpr uint8_t SDCARD_SS = 4;
LGFX display;
ScreenShot screenShot;
void setup()
{
Serial.begin(115200);
display.begin();
display.setRotation(1);
display.setBrightness(110);
display.clear(TFT_YELLOW);
// mount SD card before using
if (!SD.begin(SDCARD_SS))
Serial.println("SD Card mount failed");
// save a screenshot from the display
auto result = screenShot.saveBMP("/screenshot.bmp", display, SD);
if (!result.ok())
Serial.println(screenShotErrorString(result.error));
else
Serial.printf("Saved screenshot: %u bytes\n", result.bytesWritten);
// save a screenshot from a sprite
LGFX_Sprite sprite;
sprite.setPsram(true);
sprite.createSprite(319, 213);
sprite.setFont(&DejaVu24);
sprite.drawCenterString("Sprite", sprite.width() / 2, sprite.height() / 2);
result = screenShot.saveBMP("/spriteshot.bmp", sprite, SD);
if (!result.ok())
Serial.println(screenShotErrorString(result.error));
else
Serial.printf("Saved spriteshot: %u bytes\n", result.bytesWritten);
}
void loop()
{
delay(1000);
}- Not all displays support pixel readback.
Screenshot capture requiresreadPixel()support in LovyanGFX.
Displays without a connected MISO pin, or controllers that do not support readback cannot be used.
Check your display wiring and panel documentation if screenshots fail.