I can decode sd’s png file to png_decoded data by lodepng_decode_file() ,
but when set src to lv_img’s obj, the result that shown on the TFT seems a mistake.
How to fix the issue?
(The code as the following part.)
What MCU/Processor/Board and compiler are you using?
ESP32
lvgl 6.0.2
What do you want to achieve?
Wish to display sd’ png_file correctly.
What have you tried so far?
Code to reproduce
const char* png_filename = "/sd/images/08.PNG"; // this png file is PNG_RGBA8 type
static uint8_t* png_decoded;
uint32_t png_width, png_height;
LodePNG_format png_format=PNG_BADFORMAT;
uint8_t error = lodepng_decode_file(&png_decoded, &png_width, &png_height, &png_format, png_filename );
if(error) {
Serial.println(lodepng_error_text(error));
return;
}
Serial.printf("PNG : %s ; wxh : %dx%d ; format : %d\n", png_filename, png_width, png_height, png_format);
static lv_img_dsc_t png_dsc;
png_dsc.header.always_zero = 0; /*It must be zero*/
png_dsc.header.cf = LV_IMG_CF_TRUE_COLOR_ALPHA; /*Set the color format*/
png_dsc.header.w = png_width;
png_dsc.header.h = png_height;
png_dsc.data_size = png_width * png_height * 4;
png_dsc.data = png_decoded;
lv_obj_t * img_obj = lv_img_create(lv_scr_act(), NULL); /*Create the an image object in LittlevGL*/
lv_img_set_src(img_obj, &png_dsc);
If the other time, I want to change the img_obj to another png_file again ,
by calling lv_img_set_src() like this,
lv_img_set_src(img_obj, "/sd/images/05.png");
Or some situations , I want to delete img_obj by lv_obj_del()
The question is ,
does the lv_img’s obj automatically free previous allocated png_decoded data?
If not, how to free previous allocated png_decoded data?
On deleting the image remains open. It’s because the same image source can be used by multiple image objects.
You can clean the cache manually on delete.