- 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.
- 零點(diǎn)起飛學(xué)Xilinx FPG
- FPGA從入門(mén)到精通(實(shí)戰(zhàn)篇)
- 電腦常見(jiàn)問(wèn)題與故障排除
- BeagleBone By Example
- Unity 5.x Game Development Blueprints
- 平衡掌控者:游戲數(shù)值經(jīng)濟(jì)設(shè)計(jì)
- Mastering Manga Studio 5
- 基于Proteus仿真的51單片機(jī)應(yīng)用
- 微型計(jì)算機(jī)系統(tǒng)原理及應(yīng)用:國(guó)產(chǎn)龍芯處理器的軟件和硬件集成(基礎(chǔ)篇)
- Blender Quick Start Guide
- BeagleBone Robotic Projects
- 單片機(jī)原理及應(yīng)用:基于C51+Proteus仿真
- Raspberry Pi Home Automation with Arduino
- Applied Deep Learning with Keras
- 超炫的35個(gè)Arduino制作項(xiàng)目