How to use the JPEG decoder to display an image

Important: unclear posts may not receive useful answers.

Before posting

  • Get familiar with Markdown to format and structure your post
  • Be sure to update lvgl from the latest version from the master branch.
  • Be sure you have checked the FAQ and read the relevant part of the documentation.
  • If applicable use the Simulator to eliminate hardware related issues.

Delete this section if you read and applied the mentioned points.

Description

How do I use the new JPEG decoder in lvgl to display an Image on the screen?

What MCU/Processor/Board and compiler are you using?

ESP32-WROOM

What LVGL version are you using?

8.3.7

What do you want to achieve?

Display an image on the screen

What have you tried so far?

I have tried to use the decoder using the lv_img functions that are supposed to automatically use the decoder. I have defined the LV_USE_SJPG, the screens are being loaded but I can’t figure out how to display images on my 240x240 screen (GC9A01). Thanks!

Code to reproduce

void setup(){
//Initialized buffer and initialized lvgl

 lv_obj_t* main_screen = lv_obj_create(NULL);

  lv_scr_load(main_screen);

  lv_obj_set_style_bg_color(main_screen,lv_palette_main(LV_PALETTE_AMBER),0); // This is a check to screen has been loaded.

  lv_obj_t *img_obj = lv_img_create(main_screen);
  lv_img_set_src(img_obj,"space.jpg");
  lv_obj_set_pos(img_obj,0,0);
  lv_obj_set_size(img_obj,100,100);

  lv_scr_load(main_screen);
}

void loop(){
lv_task_handler();
}

Please check out the docs here: JPG decoder — LVGL documentation

Thank you for replying. I looked at the documentation provided as well as the documentation in the link and included the file system.

‘’‘/API for fopen, fread, etc/
#define LV_USE_FS_STDIO 1
#if LV_USE_FS_STDIO
#define LV_FS_STDIO_LETTER ‘\0’ /Set an upper cased letter on which the drive will accessible (e.g. ‘A’)/
#define LV_FS_STDIO_PATH “A” /Set the working directory. File/directory paths will be appended to it./
#define LV_FS_STDIO_CACHE_SIZE 0 />0 to cache this number of bytes in lv_fs_read()/
#endif’‘’

I also used the file system and tried to use the same functions as the example.

‘’'lv_obj_t *img_obj = lv_img_create(lv_scr_act());

lv_img_set_src(img_obj,“A:src/space.jpg”);

lv_scr_load(main_screen);‘’’

However, it did not work, I created an arc as a dummy widget to check if I had not initialized the screen correctly (happens a lot since I am still learning) but it appeared and was responsive to input. I am trying to figure out if it has to do with the file system structure of my project (using platformIO).

Thanks for replying back!

The official website has instructions for using JPEG decoders.