UPDATE:
I have discovered lvgl functions:
lv_img_buf_set_px_color
and
lv_img_buf_get_px_color
However, I cant get them to work.
For this simple experiment, I have a simple red rectangle as an png image to cover my whole display:
I have tried to do the following:
LV_IMG_DECLARE(red_square)
static lv_obj_t * ui_redsquare;
void display_red_square(){
//ui_Screen1 = lv_obj_create(NULL);
//lv_obj_clear_flag(ui_Screen1, LV_OBJ_FLAG_SCROLLABLE); /// Flags
ui_redsquare = lv_img_create(lv_scr_act());
lv_img_set_src(ui_redsquare, &red_square);
lv_obj_set_width(ui_redsquare, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_redsquare, LV_SIZE_CONTENT); /// 1
lv_obj_set_align(ui_redsquare, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_redsquare, LV_OBJ_FLAG_ADV_HITTEST); /// Flags
lv_obj_clear_flag(ui_redsquare, LV_OBJ_FLAG_SCROLLABLE); /// Flags
}
void set_img_color(){
lv_color_t c = lv_color_make(0, 255, 0);
lv_img_buf_set_px_color(ui_redsquare,50,50,c);
lv_img_buf_set_px_color(ui_redsquare,51,51,c);
lv_img_buf_set_px_color(ui_redsquare,52,52,c);
lv_img_buf_set_px_color(ui_redsquare,53,53,c);
lv_img_buf_set_px_color(ui_redsquare,54,54,c);
lv_img_buf_set_px_color(ui_redsquare,55,55,c);
lv_img_buf_set_px_color(ui_redsquare,56,56,c);
lv_img_buf_set_px_color(ui_redsquare,57,57,c);
lv_img_buf_set_px_color(ui_redsquare,58,58,c);
lv_img_buf_set_px_color(ui_redsquare,59,59,c);
}
I was expecting some of the display to change the color to green, but nothing happened.
in my main I do;
lvgl_setup();
display_red_square();
set_img_color()
I have also tried the following:
LV_IMG_DECLARE(red_square)
static lv_obj_t * ui_redsquare;
void display_red_square(){
ui_redsquare = lv_img_create(lv_scr_act());
lv_img_set_src(ui_redsquare, &red_square);
lv_obj_set_width(ui_redsquare, LV_SIZE_CONTENT); /// 1
lv_obj_set_height(ui_redsquare, LV_SIZE_CONTENT); /// 1
lv_obj_set_align(ui_redsquare, LV_ALIGN_CENTER);
lv_obj_add_flag(ui_redsquare, LV_OBJ_FLAG_ADV_HITTEST); /// Flags
lv_obj_clear_flag(ui_redsquare, LV_OBJ_FLAG_SCROLLABLE); /// Flags
}
void get_img_color(){
lv_color_t pixel_color = lv_img_buf_get_px_color(ui_redsquare, 50, 50,lv_color_make(0, 0, 0));
uint8_t red = LV_COLOR_GET_R(pixel_color);
uint8_t green = LV_COLOR_GET_G(pixel_color);
uint8_t blue = LV_COLOR_GET_B(pixel_color);
printf("Pixel color: R:%d, G:%d, B:%d \n", red, green, blue);
}
and in my main.c I do:
lvgl_setup();
display_red_square();
get_img_color();
But the printf prints:
Pixel color: R:0, G:0, B:0