Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

有没有用于缩放bitmap的api/三方库? #891

Open
Tracker647 opened this issue Aug 24, 2024 · 1 comment
Open

有没有用于缩放bitmap的api/三方库? #891

Tracker647 opened this issue Aug 24, 2024 · 1 comment

Comments

@Tracker647
Copy link

有个业务,从设备解析的数据是远大于屏幕宽度的,需要缩放。
显示控件我用的是继承mutable_image的自定义控件,但是动态显示的逻辑我是把设备数据先绘制到临时bitmap上做解码,再把临时bitmap复制到控件显示上,现在临时bitmap我是直接截的在控件高宽内部的部分,我想应该是有个api能够放缩bitmap到适应控件显示的高宽的,但看了一圈awtk好像没有,唯独一个image_set_scale是给image控件用的,基于canvas,没法给bitmap用。
我不清楚这方面有没有解决方案?

@Tracker647
Copy link
Author

可以借助awtk的离线画布去放缩,如下:

bitmap_t* helper_bitmap_resize2(bitmap_t *bmp, int new_width, int new_height) {
    canvas_t *new_bmp_canvas = canvas_offline_create(new_width, new_height, (bitmap_format_t)bmp->format);
    rect_t dst_r = rect_init(0, 0, new_width, new_height);
    rect_t src_r = rect_init(0, 0, bmp->w, bmp->h);
    canvas_draw_image(new_bmp_canvas, bmp, &src_r, &dst_r);
    bitmap_t *new_bmp_temp = canvas_offline_get_bitmap(new_bmp_canvas);
    bitmap_t *new_bmp = bitmap_clone(new_bmp_temp);
    canvas_offline_destroy(new_bmp_canvas);
    return bitmap_clone(new_bmp);
}

ret_t helper_bitmap_resize3(bitmap_t **_bmp, int new_width, int new_height) {
    bitmap_t *bmp = *_bmp;
    canvas_t *new_bmp_canvas = canvas_offline_create(new_width, new_height, (bitmap_format_t)bmp->format);
    rect_t dst_r = rect_init(0, 0, new_width, new_height);
    rect_t src_r = rect_init(0, 0, bmp->w, bmp->h);
    canvas_draw_image(new_bmp_canvas, bmp, &src_r, &dst_r);
    bitmap_t *new_bmp = canvas_offline_get_bitmap(new_bmp_canvas);
    bitmap_destroy(bmp);
    *_bmp = bitmap_clone(new_bmp);
    canvas_offline_destroy(new_bmp_canvas);
    return RET_OK;
}

之前是拿ai的算法写双线性插值,但是放大会有黑色条纹,不知道什么问题。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant