- Internet of Things Projects with ESP32
- Agus Kurniawan
- 382字
- 2021-06-24 16:02:56
Displaying image files
If you want to display an image file on the LCD, we should attach picture files in our program. For the demo, we will use picture files from the TFT library for the ESP32 library. These picture files can be found in the <project>/components/spiffs_image/image/images/ folder:
- We will continue to work with the lcddemo project by copying the disp_images() function from the TFT library into the ESP32 library. This function will show the following picture files: test1.jpg, test2.jpg, and test4.jpg.
We will load all of the images from mounted storage:
static void disp_images() {
...
// ** Show scaled (1/8, 1/4, 1/2 size) JPG images
TFT_jpg_image(CENTER, CENTER, 3, SPIFFS_BASE_PATH"/images/test1.jpg", NULL, 0);
Wait(500);
TFT_jpg_image(CENTER, CENTER, 2, SPIFFS_BASE_PATH"/images/test2.jpg", NULL, 0);
Wait(500);
TFT_jpg_image(CENTER, CENTER, 1, SPIFFS_BASE_PATH"/images/test4.jpg", NULL, 0);
Wait(500);
Then, we will show JPG images to the LCD using the TFT_jpg_image() function:
// ** Show full size JPG image
tstart = clock();
TFT_jpg_image(CENTER, CENTER, 0, SPIFFS_BASE_PATH"/images/test3.jpg", NULL, 0);
tstart = clock() - tstart;
if (doprint) printf(" JPG Decode time: %u ms\r\n", tstart);
sprintf(tmp_buff, "Decode time: %u ms", tstart);
update_header(NULL, tmp_buff);
Wait(-GDEMO_INFO_TIME);
We will also show JPG images to the LCD using the TFT_bmp_image() function:
// ** Show BMP image
update_header("BMP IMAGE", "");
for (int scale=5; scale >= 0; scale--) {
tstart = clock();
TFT_bmp_image(CENTER, CENTER, scale, SPIFFS_BASE_PATH"/images/tiger.bmp", NULL, 0);
tstart = clock() - tstart;
}
else if (doprint) printf(" No file system found.\r\n");
If there is no picture file, we print No file system found on the Terminal:
else if (doprint) printf(" No file system found.\r\n");
- Modify the tft_demo() function to call the disp_images() function, as follows:
void tft_demo() {
.....
// demo
// disp_header("Welcome to ESP32");
// circle_demo();
disp_images();
while (1) {
// do nothing
}
}
- Save all files.
- Compile and flash the program into the ESP32 board, as follows:
$ make flash
- Compile our picture files as image files:
$ make makefs
- Flash our image file into the ESP32 board:
$ make flashfs
If this succeeds, you will see image files being displayed on the LCD. You can see a sample output in Figure 2-15:

Figure 2-15: Displaying a picture from the file
Now that we've played around with the LCD, let's take the final step toward creating our weather monitoring system.
- Deep Learning with PyTorch
- 施耐德SoMachine控制器應用及編程指南
- AMD FPGA設計優化寶典:面向Vivado/SystemVerilog
- 筆記本電腦使用、維護與故障排除從入門到精通(第5版)
- Blender Quick Start Guide
- 深入理解序列化與反序列化
- IP網絡視頻傳輸:技術、標準和應用
- USB應用分析精粹:從設備硬件、固件到主機端程序設計
- 微服務實戰
- 計算機組成技術教程
- Corona SDK Mobile Game Development:Beginner's Guide
- 基于S5PV210處理器的嵌入式開發完全攻略
- The Machine Learning Workshop
- 從企業級開發到云原生微服務:Spring Boot實戰
- 嵌入式系統原理:基于Arm Cortex-M微控制器體系