Skip to content

This library allows you to take screenshots of a 16-bit RGB565 `LGFX_Sprite` or `LGFX_Device` display and save these as 24-bit BMP files on an SD card

License

Notifications You must be signed in to change notification settings

CelliesProjects/LGFX-ScreenShot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LGFX-ScreenShot

License Release Issues Last Commit PlatformIO Arduino Codacy Badge

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.

Features

  • Saves 16-bit RGB565 sources as 24-bit RGB888
  • Supports both LGFX_Sprite and LGFX_Device sources

Requirements

  • ESP32 (any variant with psram)
  • LovyanGFX
  • A mounted filesystem

Example code - save a BMP to SD card

#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);
}

Known issues

  • Some displays have hardware issues that prevent them from reading pixeldata.
    These will return false and a Display does not support readPixel() error message.
  • Currently the library only accepts RGB565 sources.

About

This library allows you to take screenshots of a 16-bit RGB565 `LGFX_Sprite` or `LGFX_Device` display and save these as 24-bit BMP files on an SD card

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages