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.
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
andLGFX_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");
String error; // returns an error message or returns unchanged on success
// save a screenshot from the display
bool success = screenShot.saveBMP("/screenshot.bmp", display, SD, error);
if (!success)
Serial.println(error); // e.g. "Display does not support readPixel()"
else
Serial.println("Saved screen");
// save a screenshot from a sprite
LGFX_Sprite sprite;
sprite.setPsram(true);
sprite.createSprite(320, 240);
sprite.setFont(&DejaVu24);
sprite.drawCenterString("Sprite", sprite.width() / 2, sprite.height() / 2);
success = screenShot.saveBMP("/spriteshot.bmp", sprite, SD, error);
if (!success)
Serial.println(error); // e.g. "Failed to open file"
else
Serial.println("Saved sprite");
}
void loop()
{
delay(1000);
}
- Some displays have hardware issues that prevent them from reading pixeldata.
These will returnfalse
and aDisplay does not support readPixel()
error message. - Currently the library only accepts RGB565 sources.