pdf-icon

Arduino Quick Start

2. Devices & Examples

Image Drawing

Image

createPng

Function Prototype:

void* createPng( size_t* datalen, int32_t x = 0, int32_t y = 0, int32_t width = 0, int32_t height = 0)

Function Description:

  • Screenshot function, saves the data displayed on the panel as PNG format in device memory.
Note:
The size of the image that can be stored depends on the memory capacity. For example, if PSRAM is disabled, high-resolution and high color depth images cannot be saved.

Parameters:

  • datalen: Length of image data
  • x: X coordinate of the screenshot starting point
  • y: Y coordinate of the screenshot starting point
  • w: Screenshot width
  • h: Screenshot height

Return:

  • void*:
  • On success: Pointer to the memory area of PNG image data
  • On failure: nullptr

Sample Program:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>

M5GFX display;
size_t png_datalen = 320 * 240;
uint8_t* PngData = (uint8_t*)malloc(png_datalen * sizeof(uint8_t));

void setup() {
    display.begin();
    display.setColorDepth(8);
    display.setRotation(1);
    display.clear(TFT_WHITE);
    display.setTextFont(&fonts::FreeSansOblique12pt7b);
    display.setTextColor(TFT_BLACK);
    delay(1000);
    uint16_t x = display.width() / 2;
    uint16_t y = display.height() / 2;

    display.drawCenterString("Create PNG Test", x, y);
    delay(2000);
    PngData = (uint8_t*)display.createPng(&png_datalen, 0, 0, 320, 240);
    display.drawCenterString("Screenshot successful", x, y+30);
    delay(2000);
    display.clear(TFT_WHITE);
    delay(1000);
    display.drawCenterString("5s later show screenshot", x, y);
    delay(5000);
    display.drawPng(PngData, png_datalen);
}

void loop() {
}

drawBmp

Function Prototype 1:

void drawBmp(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Prototype 2:

void drawBmp(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Description:

  • Draw/display BMP image

Parameters:

  • data: Pointer to image data
  • const uint8_t: Pointer to original image data
  • DataWrapper: Pointer to wrapped image data object (About DataWrapper)
  • len: Data length
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left (About datum_t)

Return:

  • null

drawBmpFile

Function Prototype 1:

void drawBmpFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Prototype 3:

void drawBmpFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Prototype 2:

void drawBmpFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Description:

  • Draw/display BMP image from BMP file

Parameters:

  • fs: File system object
  • SPIFFS
  • SD
    etc
  • path: BMP file path
  • file: Pointer to DataWrapper struct (About DataWrapper)
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left (About datum_t)

Return:

  • null

drawBmpUrl

Function Prototype:

bool drawBmpUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 
bool drawBmpUrl(String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Description:

  • Draw/display BMP image from link
Note:
To use this function, you need to write #include <HTTPClient.h> before including <M5GFX.h>.

Parameters:

  • url: Image link
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left

Return:

  • bool
  • true: Draw/display succeeded
  • false: Draw/display failed

drawJpg

Function Prototype 1:

void drawJpg(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Prototype 2:

void drawJpg(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Description:

  • Draw/display JPG image

Parameters:

  • data
  • const uint8_t: Pointer to original constant data
  • DataWrapper: Pointer to wrapped data object
  • len: Data length
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left (About datum_t)

Return:

  • null

drawJpgFile

Function Prototype 1:

void drawJpgFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Prototype 3:

void drawJpgFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Prototype 2:

void drawJpgFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Description:

  • Draw/display JPG image from JPG file

Parameters:

  • fs: File system object
  • SPIFFS
  • SD
    etc
  • path: JPG file path
  • file: Pointer to DataWrapper struct (About DataWrapper)
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left (About datum_t)

Return:

  • null

drawJpgUrl

Function Prototype:

bool drawJpgUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 
bool drawJpgUrl(String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Description:

  • Draw/display JPG image from link
Note:
To use this function, you need to write #include <HTTPClient.h> before including <M5GFX.h>.

Parameters:

  • url: Image link
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left

Return:

  • bool
  • true: Draw/display succeeded
  • false: Draw/display failed

drawPng

Function Prototype 1:

void drawPng(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Prototype 2:

void drawPng(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Description:

  • Draw/display PNG image

Parameters:

  • data
  • const uint8_t: Pointer to original constant data
  • DataWrapper: Pointer to wrapped data object
  • len: Data length
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left (About datum_t)

drawPngFile

Function Prototype 1:

void drawPngFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Prototype 3:

void drawPngFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Prototype 2:

void drawPngFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Description:

  • Draw/display PNG image from PNG file

Parameters:

  • fs: File system object
  • SPIFFS
  • SD
    etc
  • path: PNG file path
  • file: Pointer to DataWrapper struct (About DataWrapper)
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left (About datum_t)

Return:

  • null

drawPngUrl

Function Prototype:

bool drawPngUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 
bool drawPngUrl(String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Description:

  • Draw/display PNG image from link
Note:
To use this function, you need to write #include <HTTPClient.h> before including <M5GFX.h>.

Parameters:

  • url: Image link
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left

Return:

  • bool
  • true: Draw/display succeeded
  • false: Draw/display failed

drawQoi

Function Prototype 1:

void drawQoi(const uint8_t *data, uint32_t len, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Prototype 2:

void drawQoi(DataWrapper *data, int32_t x=0, int32_t y=0, int32_t maxWidth=0, int32_t maxHeight=0, int32_t offX=0, int32_t offY=0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Description:

  • Draw/display Qoi image

Parameters:

  • data
  • const uint8_t: Pointer to original constant data
  • DataWrapper: Pointer to wrapped data object
  • len: Data length
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left (About datum_t)

Return:

  • null

drawQoiFile

Function Prototype 1:

void drawQoiFile(T &fs, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Prototype 3:

void drawQoiFile(DataWrapper* file, const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Prototype 2:

void drawQoiFile(const char *path, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left)

Function Description:

  • Draw/display Qoi image from Qoi file

Parameters:

  • fs: File system object
  • SPIFFS
  • SD
    etc
  • path: Qoi file path
  • file: Pointer to DataWrapper struct (About DataWrapper)
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left (About datum_t)

Return:

  • null

drawQoiUrl

Function Prototype:

bool drawQoiUrl(const char* url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 
bool drawQoiUrl(String& url, int32_t x = 0, int32_t y = 0, int32_t maxWidth = 0, int32_t maxHeight = 0, int32_t offX = 0, int32_t offY = 0, float scale_x = 1.0f, float scale_y = 0.0f, datum_t datum = datum_t::top_left) 

Function Description:

  • Draw/display Qoi image from link
Note:
To use this function, you need to write #include <HTTPClient.h> before including <M5GFX.h>.

Parameters:

  • url: Image link
  • x: X coordinate of drawing start point
  • y: Y coordinate of drawing start point
  • maxWidth: Maximum image width
  • maxHeight: Maximum image height
  • offX: X axis offset
  • offY: Y axis offset
  • scale_x: X direction scaling ratio
  • scale_y: Y direction scaling ratio
  • datum: Image alignment, default is top left

Return:

  • bool
  • true: Draw/display succeeded
  • false: Draw/display failed
Description:
The device used in this sample program is M5Core2. Please change the SD card control pins according to the actual device used.

Sample Program:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
#include <Arduino.h>
#include <SPI.h>
#include <SD.h>
#include <M5Unified.h>
#include <M5GFX.h>

#define SD_SPI_CS_PIN   4
#define SD_SPI_SCK_PIN  18
#define SD_SPI_MISO_PIN 38
#define SD_SPI_MOSI_PIN 23

void setup() {
  M5.begin();

  M5.Display.setTextFont(&fonts::Orbitron_Light_24);
  M5.Display.setTextSize(1);

  // SD Card Initialization
  SPI.begin(SD_SPI_SCK_PIN, SD_SPI_MISO_PIN, SD_SPI_MOSI_PIN, SD_SPI_CS_PIN);
  if (!SD.begin(SD_SPI_CS_PIN, SPI, 25000000)) {
    // Print a message if SD card initialization failed or if the SD card does not exist.
    M5.Display.print("\n SD card not detected\n");
    while (1)
      ;
  } else {
    M5.Display.print("\n SD card detected\n");
  }
  delay(1000);

  M5.Display.print("\n SD card read test...\n");
  if (SD.open("/TestPicture01.png", FILE_READ, false)) {
    M5.Display.print(" PNG file 01 detected\n");
  } else {
    M5.Display.print(" PNG file 01 not detected\n");
  }
  if (SD.open("/TestPicture02.png", FILE_READ, false)) {
    M5.Display.print(" PNG file 02 detected\n");
  } else {
    M5.Display.print(" PNG file 02 not detected\n");
  }
}

void loop() {
  // Read image file and draw picture
  //         drawBmpFile
  //         drawJpgFile
  //         drawQoiFile
  M5.Display.drawPngFile(SD, "/TestPicture01.png");
  delay(1000);
  M5.Display.drawPngFile(SD, "/TestPicture02.png");
  delay(1000);
}  

This program will loop and display two PNG images from the SD card.

pushAlphaImage

Function Prototype:

void pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)

Function Description:

  • Push an image with alpha channel to the display, only supports image formats of 24 bits or higher.

Parameters:

  • x: X coordinate of the top left corner of the image
  • y: Y coordinate of the top left corner of the image
  • w: Image width
  • h: Image height
  • param: Pointer to pixelcopy_t struct, containing image data and other parameters
  • data: Pointer to image pixel data

Return:

  • null

pushGrayscaleImage

Function Prototype 1:

void pushGrayscaleImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor)

Function Description:

  • Push a grayscale image to the display

Parameters:

  • x: X coordinate of the top left corner of the image
  • y: Y coordinate of the top left corner of the image
  • w: Image width
  • h: Image height
  • image: Pointer to image data
  • depth: Image color depth
  • forecolor: Foreground color
  • backcolor: Background color

Return:

  • null

pushGrayscaleImageAffine

Function Prototype:

void pushGrayscaleImageAffine(const float matrix[6], int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor)

Function Description:

  • Push a grayscale image to the display with affine transformation

Parameters:

  • matrix: Array of 6 floats, affine transformation matrix
  • w: Image width
  • h: Image height
  • image: Pointer to image data
  • depth: Image color depth
  • forecolor: Foreground color
  • backcolor: Background color

Return:

  • null

pushGrayscaleImageRotateZoom

Function Prototype:

void pushGrayscaleImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const uint8_t* image, color_depth_t depth, const T& forecolor, const T& backcolor)

Function Description:

  • Push a grayscale image to the display with affine transformation

Parameters:

  • dst_x: X coordinate of the top left corner of the output image
  • dst_y: Y coordinate of the top left corner of the output image
  • src_x: X coordinate of the top left corner of the source image
  • src_y: Y coordinate of the top left corner of the source image
  • angle: Rotation angle (in radians)
  • zoom_x: X direction scaling ratio
  • zoom_y: Y direction scaling ratio
  • w: Image width
  • h: Image height
  • image: Pointer to image data
  • depth: Image color depth
  • forecolor: Foreground color
  • backcolor: Background color

Return:

  • null

pushImage

Function Prototype 1:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)

Function Prototype 2:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const T1* data, const T2& transparent)

Function Prototype 3:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

Function Prototype 4:

void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

Function Description:

  • Push an image to the display

Parameters:

  • x: X coordinate of the top left corner of the image
  • y: Y coordinate of the top left corner of the image
  • w: Image width
  • h: Image height
  • data: Pointer to image pixel data
  • transparent: Transparent color
  • depth: Image color depth
  • palette: Pointer to palette

Return:

  • null

pushImageDMA

Function Prototype 1:

void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)

Function Prototype 2:

void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

Function Description:

  • Push an image to the display using DMA

Parameters:

  • x: X coordinate of the top left corner of the image
  • y: Y coordinate of the top left corner of the image
  • w: Image width
  • h: Image height
  • data: Pointer to image pixel data
  • depth: Image color depth
  • palette: Pointer to palette

Return:

  • null

pushImageAffine

Function Prototype 1:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const T* data)

Function Prototype 2:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const T1* data, const T2& transparent)

Function Prototype 3:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

Function Prototype 4:

void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

Function Description:

  • Push an image to the display using affine transformation

Parameters:

  • matrix: Array of 6 floats, affine transformation matrix
  • w: Image width
  • h: Image height
  • data: Pointer to image pixel data
  • transparent: Transparent color
  • depth: Image color depth
  • palette: Pointer to palette

Return:

  • null

pushImageAffineWithAA

Function Prototype 1:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const T* data)

Function Prototype 2:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const T1* data, const T2& transparent)

Function Prototype 3:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

Function Prototype 4:

void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

Function Description:

  • Push an image to the display with anti-aliasing affine transformation

Parameters:

  • matrix: Array of 6 floats, affine transformation matrix
  • w: Image width
  • h: Image height
  • data: Pointer to image pixel data
  • transparent: Transparent color
  • depth: Image color depth
  • palette: Pointer to palette

Return:

  • null

pushImageRotateZoom

Function Prototype 1:

void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T* data)

Function Prototype 2:

void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T1* data, const T2& transparent)

Function Prototype 3:

void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

Function Prototype 4:

void pushImageRotateZoom(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

Function Description:

  • Push an image to the display after rotation and zoom

Parameters:

  • dst_x: X coordinate of the top left corner of the output image
  • dst_y: Y coordinate of the top left corner of the output image
  • src_x: X coordinate of the top left corner of the source image
  • src_y: Y coordinate of the top left corner of the source image
  • angle: Rotation angle (in radians)
  • zoom_x: X direction scaling ratio
  • zoom_y: Y direction scaling ratio
  • w: Image width
  • h: Image height
  • data: Pointer to image pixel data
  • transparent: Transparent color
  • depth: Image color depth
  • palette: Pointer to palette

Return:

  • null

pushImageRotateZoomWithAA

Function Prototype 1:

void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T* data)

Function Prototype 2:

void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const T1* data, const T2& transparent)

Function Prototype 3:

void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)

Function Prototype 4:

void pushImageRotateZoomWithAA(float dst_x, float dst_y, float src_x, float src_y, float angle, float zoom_x, float zoom_y, int32_t w, int32_t h, const void* data, uint32_t transparent, color_depth_t depth, const T* palette)

Function Description:

  • Push an image to the display with anti-aliasing after rotation and zoom

Parameters:

  • dst_x: X coordinate of the top left corner of the output image
  • dst_y: Y coordinate of the top left corner of the output image
  • src_x: X coordinate of the top left corner of the source image
  • src_y: Y coordinate of the top left corner of the source image
  • angle: Rotation angle (in radians)
  • zoom_x: X direction scaling ratio
  • zoom_y: Y direction scaling ratio
  • w: Image width
  • h: Image height
  • data: Pointer to image pixel data
  • transparent: Transparent color
  • depth: Image color depth
  • palette: Pointer to palette

Return:

  • null

Image Color Conversion

setSwapBytes

Function Prototype:

void setSwapBytes(bool swap)

Function Description:

  • Set byte swap state

Parameters:

  • swap: Byte swap state
    • true: Swap bytes
    • false: Do not swap bytes

Return:

  • null

getSwapBytes

Function Prototype:

bool getSwapBytes(void)

Function Description:

Parameters:

  • null

Return:

  • bool: Byte swap state
    • true: Swapped
    • false: Not swapped

swap565

Function Prototype:

uint16_t swap565( uint8_t r, uint8_t g, uint8_t b)

Function Description:

  • Generate color code from R, G, B components

Parameters:

  • r: Red component, 0-255
  • g: Green component, 0-255
  • b: Blue component, 0-255

Return:

  • uint16_t: RGB565 color code

swap888

Function Prototype:

uint16_t swap888( uint8_t r, uint8_t g, uint8_t b)

Function Description:

  • Generate color code from R, G, B components

Parameters:

  • r: Red component, 0-255
  • g: Green component, 0-255
  • b: Blue component, 0-255

Return:

  • uint32_t: RGB888 color code

Sample Program:

cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#include <Arduino.h>
#include <M5GFX.h>
#include <M5Unified.h>

M5GFX display;
uint16_t PngData[1600];
static float Affine_mat[9] = {1, 0, 0,
                              0, 1, 60,
                              0, 0, 1  };

void setup() {
    display.begin();
    display.setColorDepth(24);
    display.setRotation(1);
    display.clear(TFT_WHITE);
    display.setTextFont(&fonts::FreeSansOblique12pt7b);
    display.setTextColor(0xF81F);
    delay(1000);
    uint16_t x = display.width() / 2;
    uint16_t y = display.height() / 2;
    // display.setSwapBytes(true);//If you want to directly assign a 16-bit color code in the lower code section, you need to enable this line of code.
    for (int i = 0; i < 1600; ++i) PngData[i] = display.swap565( 255, 0, 0);//After swapping, it becomes BGR565.

    display.drawCenterString("Push Image Test", x, 10);
    delay(2000);
    display.pushImage(0, y, 320, 5, PngData);
    // display.pushImageDMA(0, y, 320, 5, PngData);
    // Shift 60 units from the origin(0,0) using the affine matrix
    // display.pushImageAffine(Affine_mat, 320, 5, PngData, 80);
    display.pushImageAffineWithAA(Affine_mat, 320, 5, PngData, 40);
    // Rotate and Zoom, by comparing on the screen, you can see the effect of anti-aliasing.
    display.pushImageRotateZoom(x, y, 0, 0, 37, 2, 2, 320, 5, PngData);
    display.pushImageRotateZoomWithAA(x, y, 0, 4, 143, 2, 2, 320, 5, PngData);
}

void loop() {
}
On This Page