Unexpected pixel content is rendered when the picture is zoomed
PC, 7.1.0
What do you experience?
when i create a image (lv_img_create) and zoom it, the image render result contains unexpected pixel part.
origin image is a png file, size of 64x64
zoom is 1.25 * 255
What do you expect?
image only draw what i need, dont render repeat part.
my solution:
i modified the lv_img.c file, to render the correct result.
and i can’t understand the porpuse of the origin code blow:
origin code, file: lv_img.c , line 653:
for(; cords_tmp.y1 <= img_coords.y2; cords_tmp.y1 += ext->h, cords_tmp.y2 += ext->h) {
cords_tmp.x1 = img_coords.x1;
cords_tmp.x2 = img_coords.x1 + ext->w - 1;
for(; cords_tmp.x1 <= img_coords.x2; cords_tmp.x1 += ext->w, cords_tmp.x2 += ext->w) {
lv_draw_img(&cords_tmp, clip_area, ext->src, &img_dsc);
}
}
my solution code:
diff --git a/src/lv_widgets/lv_img.c b/src/lv_widgets/lv_img.c
index 6c6f6579..83e985ee 100644
--- a/src/lv_widgets/lv_img.c
+++ b/src/lv_widgets/lv_img.c
@@ -650,12 +650,6 @@ static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area
}
if(ext->src_type == LV_IMG_SRC_FILE || ext->src_type == LV_IMG_SRC_VARIABLE) {
- img_coords.x1 += ext->offset.x;
- img_coords.y1 += ext->offset.y;
-
- if(img_coords.x1 > img->coords.x1) img_coords.x1 -= ext->w;
- if(img_coords.y1 > img->coords.y1) img_coords.y1 -= ext->h;
-
LV_LOG_TRACE("lv_img_design: start to draw image");
lv_draw_img_dsc_t img_dsc;
@@ -673,16 +667,12 @@ static lv_design_res_t lv_img_design(lv_obj_t * img, const lv_area_t * clip_area
img_dsc.antialias = ext->antialias;
lv_area_t cords_tmp;
+ cords_tmp.x1 = img_coords.x1;
+ cords_tmp.x2 = img_coords.x1 + ext->w - 1;
cords_tmp.y1 = img_coords.y1;
cords_tmp.y2 = img_coords.y1 + ext->h - 1;
- for(; cords_tmp.y1 <= img_coords.y2; cords_tmp.y1 += ext->h, cords_tmp.y2 += ext->h) {
- cords_tmp.x1 = img_coords.x1;
- cords_tmp.x2 = img_coords.x1 + ext->w - 1;
- for(; cords_tmp.x1 <= img_coords.x2; cords_tmp.x1 += ext->w, cords_tmp.x2 += ext->w) {
- lv_draw_img(&cords_tmp, clip_area, ext->src, &img_dsc);
- }
- }
+ lv_draw_img(&cords_tmp, clip_area, ext->src, &img_dsc);
}
else if(ext->src_type == LV_IMG_SRC_SYMBOL) {
Code to reproduce
auto widget = lv_obj_create(lv_scr_act(), nullptr);
lv_obj_set_size(widget, 80, 80);
lv_obj_set_pos(widget, 200, 200);
lv_obj_set_style_local_border_opa(widget, 0, 0, LV_OPA_COVER);
lv_obj_set_style_local_border_color(widget, 0, 0, LV_COLOR_RED);
lv_obj_set_style_local_border_width(widget, 0, 0, 1);
auto img = lv_img_create(widget, nullptr);
lv_obj_set_size(img, 80, 80);
lv_img_set_auto_size(img, false);
lv_img_set_zoom(img, 1.25 * LV_IMG_ZOOM_NONE);
lv_img_set_src(img, "path of img_1.png");