I use LVGL but I can' show my gif on one Brain

Hello guys! I recently tried to ported LVGL to vexcode text (I use VEX Expenision in VSCode), by using James Pearman’project.It really helps me a lot, because it helps me to display imgs without a SDCard.
If I don’t use gif, it worked out pretty well. However,when it comes to gif playing.I screwed up.Even if I change the lv_conf.h ,the gif just can’t be played.

Here is GIF Function code:

void PicShow(){
  LV_IMG_DECLARE(bad_apple_cut_raw);              //I use the online imageconverter from offical
  lv_obj_t* img = lv_gif_create(lv_scr_act());   //I'll talk about that later
  lv_gif_set_src(img, &bad_apple_cut_raw);
  lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);

Here is my code to call the function:

///this int function runs in a muti-task.It works fine
int PreAutoChart(){
  //========== LVGLTest ==============

  while(!game_start) {  

  return 0;

Just like what I have mentioned in the code. “bad_apple_cut_raw” is a "c file ",which I get from Online image converter - BMP, JPG or PNG to C array or binary | LVGL
I transform my gif in settings like this,

exactly the way as the offical docs says.

However, when I download the program and run it ,I looks like this:
The GIF disapper for no reason.But if I use the demo provided by LVGL Offical,it works fine.
Here is the code:

void PicShow(){
  lv_obj_t * img;

  img = lv_gif_create(lv_scr_act());
  lv_gif_set_src(img, &img_bulb_gif);
  lv_obj_align(img, LV_ALIGN_LEFT_MID, 20, 0);

offical demo

This has bothered me for 2 days.And I still have no ideas about how to solve it.Pleas help!
I really want to use cutom gif.


@jpearman Do you do something with the gif part in the lvgl?Pls help

If you want to send me the project (zip up the project folder) and the image I will try and have a look over the next couple of days. If you want to keep it private post here and I will DM you.


Thanks for your checking my code. I’m really sorry to keep you waiting for so long. I am still a student and need to study. I would really appreciate it if you can give me a solution. Here’s my code.Hope you have a good day!
Problems.zip (17.1 MB)

I had a look at this. First thing to do when debugging is turn on LVGL logging, set

#define LV_USE_LOG 1


#define LV_LOG_PRINTF 1

then you will see output in the terminal window if there are issues. I see

[Warn]	(0.000, +0)	 gif_open: no global color table
 	(in gifdec.c line #97)
[Warn]	(0.000, +0)	 lv_gif_set_src: Could't load the source 	(in lv_gif.c line #78)

so the original animated gif is missing the global color table that this decoder needs.
I hacked a version for you here. (opened in preview, exported and then had to fix the gif header slightly)

bad_apple_cut_raw.c.zip (2.0 MB)



Thanks for solving my problem.

But through your words, it seems to be a gif problem.You gave me a solution to slove it.But unluckily , my silly brain and my bad English(I tried to use translator, but it soon turned out that it was useless and I can’t still understan it) prevents me from understanding the sentence “opened in preview, exported and then had to fix the gif header slightly”
So does that mean open a gif and save as to fix the gif ?If not, could you please explain again?

Thanks for your patience!

1 Like

yes, the original gif file was in a format that the gif decoder in LVGL doesn’t handle.

I needed a quick way to add the global color table to the original gif (bad_apple_cut.gif). I’m sure there is something online, but the first thing I tried was to open in a Mac program called “preview” that’s used to view images, then I exported as a new file (and converted to C array using LVGL converter), this (apparently) fixed the global color table issue but preview saved the file as “GIF87a” (the first 6 bytes) and the gifdec.c code only want’s to accept “GIF89a”

    /* Header */
    f_gif_read(gif_base, sigver, 3);
    if (memcmp(sigver, "GIF", 3) != 0) {
        LV_LOG_WARN("invalid signature\n");
        goto fail;
    /* Version */
    f_gif_read(gif_base, sigver, 3);
    if (memcmp(sigver, "89a", 3) != 0) {
        LV_LOG_WARN("invalid version\n");
        goto fail;

It was just easier to change the 7 (0x37) to a 9 (0x39) in the bad_apple_cut_raw.c file rather than mess with the gif decoding code.


Thanks for your advice and explanations.Now I understand what you mean and the solution.
Have a nice day!

hello,Can you tell me how it works?I look forward to showing the pictures on the Brain,Looks like a good way to show pictures and gifs.If you can use qq, please tell me by this way(3105950984).(I don’t often browse the forum.)thank you( '▿ ’ )