Description
I created the first lv_img’s obj that has a source from PNG file.
And I copied to the second one, but the second one can’t show anything.
What MCU/Processor/Board and compiler are you using?
What do you want to achieve?
File-type source of the first lv_img’s obj is copied to the second one too.
What have you tried so far?
Code to reproduce
lv_obj_t *first_img;
lv_obj_t *second_img;
const char* src_file = "/sd/pictures/png_file.png";
first_img= lv_img_create(lv_scr_act(),NULL);
lv_img_set_src(first_img, src_file);
lv_obj_set_pos(first_img,0,0);
lv_obj_set_hidden(first_img, true);
second_img= lv_img_create(lv_scr_act(), first_img);
lv_obj_set_pos(second_img,180,0);
Screenshot and/or video
I am not a expert, but try,
const char src_file[ ] = “/sd/pictures/png_file.png”;
or
const char src_file[ ] = “/sd/pictures/png_file.png”;
const char* src_file_pointer = &src_file;
Thank you.
The problem is not by char* variable.
The first lv_img’s obj can work well when set by
lv_img_set_src(first_img, src_file);
But the second lv_img’s obj that if created by copying with
second_img = lv_img_create(lv_scr_act(), first_img);
The source of the first if its type is LV_IMG_SRC_FILE
doesn’t seem copy to the second as it should to be.
can you put a screenshot?
If you debug, in lv_img_create
function, do you get to this line? :
lv_img_set_src(new_img, copy_ext->src);
CODE Test1
Test by the first lv_img’obj only, it can display well
lv_obj_t *first_img;
const char* src_file = "/sd/pictures/png_file.png";
first_img= lv_img_create(lv_scr_act(),NULL);
lv_img_set_src(first_img, src_file);
lv_obj_set_pos(first_img,0,0);

CODE Test2
Test by copying the first obj to the second. And hidden the first.
The second can’t display anything.
(My screen’s background set to black color.)
lv_obj_t *first_img;
lv_obj_t *second_img;
const char* src_file = "/sd/pictures/png_file.png";
first_img= lv_img_create(lv_scr_act(),NULL);
lv_img_set_src(first_img, src_file);
lv_obj_set_pos(first_img,0,0);
lv_obj_set_hidden(first_img, true);
second_img= lv_img_create(lv_scr_act(), first_img);
lv_obj_set_pos(second_img,180,0);

I think the second one is hidden too. because the hidden
property is copied to the second_img from first_img.
so add this:
lv_obj_set_hidden(second_img, true);
after the creation of second_img
or hide the first one, after you create the second one.
1 Like
New knowledge for me,
when create by copying, the hidden attrib is also copied.
Thank you.