简体   繁体   中英

How can I call random jpg from sd card and display using drawSdJpeg

In the TFT_ESPI (Bodmer) Example/Generic/ESP32_SDcard_jpeg

I have run it on my esp32 on a 3.5" ili9341 with no problems. I have changed the sd file names to numbers and called them as such... drawSdJpeg("/1.jpg", 0, 0); and as expected, runs the same.

I have used this code to display the images one after another...

`File file;
File root = SD.open("/");
if(!root){
Serial.println("Failed to open root directory");
return;
}
file = root.openNextFile(); // Opens next file in root
while(file)
{
if(!file.isDirectory())
{
drawSdJpeg(file.name(), 0, 0); // This draws a jpeg pulled off the SD Card
delay(4000);
}
file = root.openNextFile(); // Opens next file in root
}
root.close();`

But I can't find a way to call a RANDOM file (image) and display it.

Can anyone help please, I would appreciate it. Thank you.

And thank you to Bodmer for making many things possible !

SOLVED Thanks to Bodmer

Yes, the drawSdJpeg function expects a string, so you need to create a string with the number in it plus the.jpg extension. For example:

char filename [20]; // 19 chars max + terminating null
int i = 42;
itoa(i,filename,10); // Put string version of a number in filename, 
number base 10
strcat(filename, ".jpg"); // add .jpg to end of string
drawSdJpeg(filename, 0, 0); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM