函数原型:
void* createPng( size_t* datalen, int32_t x = 0, int32_t y = 0, int32_t width = 0, int32_t height = 0)
功能说明:
传入参数:
返回值:
案例程序:
#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() {
}
函数原型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)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型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)
函数原型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)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型:
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)
功能说明:
<M5GFX.h>
之前写入 #include <HTTPClient.h>
。传入参数:
返回值:
函数原型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)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型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)
函数原型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)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型:
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)
功能说明:
<M5GFX.h>
之前写入 #include <HTTPClient.h>
。传入参数:
返回值:
函数原型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)
函数原型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)
功能说明:
传入参数:
函数原型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)
函数原型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)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型:
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)
功能说明:
<M5GFX.h>
之前写入 #include <HTTPClient.h>
。传入参数:
返回值:
函数原型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)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型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)
函数原型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)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型:
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)
功能说明:
<M5GFX.h>
之前写入 #include <HTTPClient.h>
。传入参数:
返回值:
M5Core2
,请根据实际使用设备更改SD卡控制引脚。案例程序:
#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);
}
该程序会循环播放 SD 卡中的两张 PNG 图片。
函数原型:
void pushAlphaImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)
功能说明:
传入参数:
返回值:
函数原型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)
功能说明:
传入参数:
返回值:
函数原型:
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)
功能说明:
传入参数:
返回值:
函数原型:
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)
功能说明:
传入参数:
返回值:
函数原型1:
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)
函数原型2:
void pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const T1* data, const T2& transparent)
函数原型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)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型1:
void pushImageDMA(int32_t x, int32_t y, int32_t w, int32_t h, const T* data)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型1:
void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const T* data)
函数原型2:
void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const T1* data, const T2& transparent)
函数原型3:
void pushImageAffine(const float matrix[6], int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型1:
void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const T* data)
函数原型2:
void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const T1* data, const T2& transparent)
函数原型3:
void pushImageAffineWithAA(const float matrix[6], int32_t w, int32_t h, const void* data, color_depth_t depth, const T* palette)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型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)
函数原型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)
函数原型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)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型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)
函数原型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)
函数原型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)
函数原型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)
功能说明:
传入参数:
返回值:
函数原型:
void setSwapBytes(bool swap)
功能说明:
传入参数:
返回值:
函数原型:
bool getSwapBytes(void)
功能说明:
传入参数:
返回值:
函数原型:
uint16_t swap565( uint8_t r, uint8_t g, uint8_t b)
功能说明:
传入参数:
返回值:
函数原型:
uint16_t swap888( uint8_t r, uint8_t g, uint8_t b)
功能说明:
传入参数:
返回值:
案例程序:
#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() {
}