Git Product home page Git Product logo

Comments (4)

W-Mai avatar W-Mai commented on July 2, 2024 1

@W-Mai I just saw that the docs of the image caching is outdated here. Do you have time to update it?

Oh, sure, let me be in charge of this.

from lvgl.

kisvegabor avatar kisvegabor commented on July 2, 2024

Does the UI still work after changing the image?

Please try these:

  • call lv_obj_invalidate(imgobj_qr1)
  • call lv_image_cache_drop("C:/decoded_image.png");
  • set LV_CACHE_DEF_SIZE 0 in lv_conf.h
  • try saving the image with a different name

from lvgl.

Neothai avatar Neothai commented on July 2, 2024

Thank you for the good advice. I did the test as you suggested and got results like this.

Does the UI still work after changing the image

Yes, the UI and other objects still work normally.


call lv_obj_invalidate(imgobj_qr1)

I have tried doing this

...
lv_image_set_src(imgobj_qr1, "C:/decoded_image.png");
lv_obj_align(imgobj_qr1, LV_ALIGN_CENTER, 0, 0);

lv_obj_invalidate(imgobj_qr1); // <---

But still nothing has changed.


call lv_image_cache_drop("C:/decoded_image.png");

It works, but needs to call lv_image_cache_drop("C:/decoded_image.png"); before creating an image like this.

lv_image_cache_drop("C:/decoded_image.png"); //<--
if(lv_obj_is_valid(imgobj_qr1)){lv_obj_delete_async(imgobj_qr1); Serial.println("del old1------------------------");}
imgobj_qr1 = lv_image_create(lv_screen_active()); Serial.println("create new1");
...
lv_image_set_src(imgobj_qr1, "C:/decoded_image.png");
lv_obj_align(imgobj_qr1, LV_ALIGN_CENTER, 0, 0);

set LV_CACHE_DEF_SIZE 0 in lv_conf.h`

I originally set this to

#define LV_MEM_SIZE                   (3072U * 1024U) // Allocate on PSRAM

#define LV_CACHE_DEF_SIZE             (1500U * 1024U)
#define LV_IMAGE_HEADER_CACHE_DEF_CNT (512U * 1024U)

When changed to

#define LV_MEM_SIZE                   (3072U * 1024U) // Allocate on PSRAM

#define LV_CACHE_DEF_SIZE             0
#define LV_IMAGE_HEADER_CACHE_DEF_CNT 0

It works too. But it takes a very long time to draw and the file is constantly being read (for large images).


try saving the image with a different name

It works too (when LV_CACHE_DEF_SIZE and LV_IMAGE_HEADER_CACHE_DEF_CNT are not 0), but images in the old cache are not cleared when changing to new images. Then the cache will be full when changing the image to a new one within 3-4 times.


In conclusion, I think your suggestion call lv_image_cache_drop("C:/decoded_image.png"); is the best solution.

And this would be great if in the documentation https://docs.lvgl.io/master/libs/lodepng.html it was suggested to add lv_image_cache_drop(imageSrc); before loading new images.

Thanks again for the great solution to this problem. 😊

from lvgl.

kisvegabor avatar kisvegabor commented on July 2, 2024

Awesome! 🎉

Actually it's related to images in general, because LVGL caches images by file name (or pointer in case of variables). So if you change the content of the image you need to tell LVGL to re-cache it.

@W-Mai I just saw that the docs of the image caching is outdated here. Do you have time to update it?

from lvgl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.