Display images on V5 Screen

I recently started using LVGL on PROs and so far I was able to make an auton selector. To make it cooler, I was wondering if there is a way to display images on the screen and how can I do it.

Yep. Look at the LVGL docs.
I have not managed to get the SD Card method to work, but the image convertor method works.
Since pros has an older version, use the old convertor.
Make sure you resize your image to the dimensions of the V5 (480x240).


I have not managed to get the SD Card method to work, but the image convertor method works.

When I attempt to use the imported images, I am given an error.

error: expected primary-expression before ‘.’ token
.header.w = 135, /*Image width in pixel count*/

How do I change the code to avoid this?

Make sure you are using the converter that is made for the version of LVGL that PROS uses (which is not the latest version).

I used the old version here which says that it is for version 5.1.1. It gave me a c file that had an array of the image and ended with this definition:

const lv_img_t DogLogo = {
.header.w = 135, /*Image width in pixel count*/
.header.h = 150, /*Image height in pixel count*/
.header.alpha_byte = 0, /*No alpha byte*/
.header.chroma_keyed = 1, /*LV_COLOR_TRANSP (lv_conf.h) pixels will be transparent*/
.header.format = LV_IMG_FORMAT_INTERNAL_RAW, /*It’s a variable compiled into the code*/
.pixel_map = DogLogo_pixel_map /*Pointer the array of image pixels.*/

The parts with “.header” and “.pixel_map” are causing an error. I think this is because there is nothing before the “.”, but it could be the way I am including the c file from the conversion. I am including it as a renamed .h file at the start of my display code. I am not exactly sure of the correct way to include it in the main code body. I also attempted the advice listed here, but it did not work.

The issue is that the syntax the LVGL convertor uses was introduced in a new version of the C standard. However, C++ has not included that standard.
Yes, your issue is because of the way you included it.
You should read learncpp.com to learn how the compiler compiles each source file in a project individually and how to share variables between files.
The LVGL website tells you specifically how to do it.
All you need to do is keep the file as .c, the compiler will compile it separately, and then to use it in your file you need to call LV_IMG_DECLARE(my_image_name); and it will forward declare the image.

In my post you linked, only the first method will work. However, you won’t need to do that if you do what the convertor says.

1 Like

This worked great. Another issue I had is that the converter did not properly convert .bmp files for me, but a png worked fine. Thanks a ton!

@theol0403 is this still the case for loading images in PROS since the newest update?
If so, where do you need to forward declare the image (in the main.cpp source file or in the C array file)?

I’m still a bit confused on the process
Thanks in advance

I have not used the latest version of the convertor, but I believe so.
Have you read the docs? They will answer your second question.
You want to have the forward declaration in your user code, that’s what lets your code know that the array exists in another file.