How to force to reload my image

Hello,
I made a screen composed of buttons and images. The background image is load and then the button.

Only the button are refresh. Here is the code I use to refresh my image :slight_smile:


  if (!image_load(image, image_path)) {
    return false;
  }

  if (obj == NULL) { obj = lv_img_create(parent, NULL); }

  lv_obj_add_style(obj, LV_IMG_PART_MAIN, style);
  lv_obj_set_pos(obj, px, py);
  lv_obj_set_size(obj, width, height);
  lv_obj_set_click(obj, true);
  background->data = image->data;
  lv_img_set_src(obj, background);
  lv_img_set_pivot(obj, 0, 0);
  lv_img_set_angle(obj, 0);

  lv_img_set_src(obj, background);

  ///////////
  // Load focused image
  char image_path[512];
  strcpy(image_path, folder_image_path);
  strcat(image_path, "/image_0.png");

  if (!image_load(image_focused, image_path)) {
    return false;
  }
  background_focused->data = image_focused->data;

  ///////////
  // Load defocused image
  strcpy(image_path, folder_image_path);
  strcat(image_path, "/image2.png");


  if (!image_load(image_defocused, image_path)) {
    return false;
  }
  background_defocused->data = image_defocused->data;

  LOGI(TAG, "screen_button_load: Create button object00");

  if (obj == NULL) {
    LOGI(TAG, "screen_button_load: Create button object");
    obj = (lv_obj_t*) malloc(sizeof(lv_obj_t));
    obj = lv_imgbtn_create(parent, NULL);
    lv_obj_add_style(obj, LV_IMGBTN_PART_MAIN, style);
    lv_obj_set_pos(obj, px, py);
    lv_obj_set_size(obj, width, height);
  }

  lv_imgbtn_set_src(obj, LV_BTN_STATE_RELEASED, background_defocused);
  lv_imgbtn_set_src(
      obj, LV_BTN_STATE_CHECKED_RELEASED, background_defocused);
  lv_imgbtn_set_src(obj, LV_BTN_STATE_PRESSED, background_focused);
  lv_imgbtn_set_src(
      obj, LV_BTN_STATE_CHECKED_PRESSED, background_focused);
  lv_imgbtn_set_checkable(obj, true);

My problem is my background is not refresh but the foreground buttons are refresh.

Hi,

Try lv_img_cache_invalidate_src(NULL);.

Thank you for the answer

Was it working?

Yes it works properly. Thank you.