Skip to content

CelliesProjects/LGFX-ScreenShot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 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.
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.

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");

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

Known issues

  • Not all displays support pixel readback.
    Screenshot capture requires readPixel() 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.

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

 
 
 

Contributors

Languages