图像 (Img)
图像控件是用于显示图像的基本控件,支持移动、缩放、旋转等功能。
用法
创建控件
开发者可以使用 gui_img_create_from_mem()
从内存中创建一个图像控件,或者使用 gui_img_create_from_fs()
从文件系统中创建一个图像控件。同样,也可以使用 gui_img_create_from_ftl()
从闪存中创建一个图像控件。
如果图像控件的宽度或高度设置为 0,那么控件的大小将根据图像源的大小自动设置。
设置焦点
图片控件的默认焦点位置位于图片的左上角 (0, 0),开发者可以使用 gui_img_set_focus()
设置新的图片控件的焦点,设置完成之后,图片控件的变换、旋转、平移操作都会基于新的焦点进行。
设定属性
开发者可以通过 gui_img_set_attribute()
来设置图像控件的属性,替换为新图像并设置新坐标。
获取高度/宽度
如果想要获取图像控件的高度/宽度,开发者可以使用 gui_img_get_height()
或 gui_img_get_width()
。
刷新大小
开发者可以调用 gui_img_refresh_size()
来刷新图像控件大小。
混合模式
开发者可以使用 gui_img_set_mode()
来设定图像控件的混合模式。
移动
通过 gui_img_translate()
来移动图像控件。
开发者可以将图像控件移动到新坐标,而不改变控件属性中的原始坐标。
旋转
开发者可以通过 gui_img_rotation()
来围绕圆心旋转图像控件。
缩放
开发者可以使用 gui_img_scale()
调整图像控件的大小以满足需求。
不透明度
图像控件的不透明度值是可调整的,开发者可以调用 gui_img_set_opacity()
来调整。
质量
开发者可以调用 gui_img_set_quality()
来设定图像控件的显示质量。
截屏
开发者可以使用 gui_img_tree_convert_to_img()
来保存全屏截图。保存的图像会是 RGB 格式。
示例
void test_event_cb(void *obj, gui_event_t e, void *param)
{
GUI_UNUSED(e);
GUI_UNUSED(param);
gui_obj_t *this = (gui_obj_t *)obj;
gui_log("Event test obj name = %s, e = 0x%x !\n", this->name, e);
}
void test_timer_cb(void *param)
{
GUI_UNUSED(param);
gui_log("timer cb test!\n");
}
#include "gifdec.h"
static int app_init(void)
{
void *addr = (void *)_actiger_blue_compressed;
// void *addr = (void *)_acgreen;
// void *addr = (void *)_acgif_demo;
gui_img_t *img = gui_img_create_from_mem(gui_obj_get_root(), "img_1_test", addr, 0, 0, 0, 0);
gui_img_set_focus(img, 50, 50);
gui_img_rotation(img, 45.0f);
gui_img_translate(img, 50, 50);
// gui_obj_add_event_cb(img, (gui_event_cb_t)test_event_cb, GUI_EVENT_TOUCH_CLICKED, NULL);
// gui_obj_create_timer(&(img->base), 1000, true, test_timer_cb);
// gui_obj_start_timer(&(img->base));
return 0;
}
GUI_INIT_APP_EXPORT(app_init);

API
Functions
-
uint16_t gui_img_get_width(gui_img_t *_this)
-
Load the image to read its width.
- 参数:
-
this – The image widget pointer.
- 返回:
-
uint16_t Image’s width.
-
uint16_t gui_img_get_height(gui_img_t *_this)
-
Load the image to read its height.
- 参数:
-
this – The image widget pointer.
- 返回:
-
uint16_t Image’s height.
-
void gui_img_refresh_size(gui_img_t *_this)
-
Refresh the image size from source.
- 参数:
-
this – The image widget pointer.
-
void gui_img_set_mode(gui_img_t *_this, BLEND_MODE_TYPE mode)
-
Set the image’s blend mode.
- 参数:
this – The image widget pointer.
mode – The enumeration value of the mode (BLEND_MODE_TYPE).
-
void gui_img_set_attribute(gui_img_t *_this, const char *name, void *addr, int16_t x, int16_t y)
-
Set image attributes (name, path, position).
- 参数:
this – Image widget pointer.
name – Widget name.
addr – Image address/path.
x – X-axis coordinate.
y – Y-axis coordinate.
-
void gui_img_rotation(gui_img_t *_this, float degrees)
-
Rotate the image around its center.
- 参数:
this – The image widget pointer.
degrees – Clockwise rotation absolute angle.
-
void gui_img_scale(gui_img_t *_this, float scale_x, float scale_y)
-
Scale the image, taking (0,0) as the zoom center.
- 参数:
this – The image widget pointer.
scale_x – Scale factor in X direction.
scale_y – Scale factor in Y direction.
-
void gui_img_translate(gui_img_t *_this, float t_x, float t_y)
-
Translate (move) the image.
- 参数:
this – The image widget pointer.
t_x – New X-axis coordinate.
t_y – New Y-axis coordinate.
-
void gui_img_skew_x(gui_img_t *_this, float degrees)
-
Skew the image on X-axis.
- 参数:
this – The image widget pointer.
degrees – Skew angle.
-
void gui_img_skew_y(gui_img_t *_this, float degrees)
-
Skew the image on Y-axis.
- 参数:
this – The image widget pointer.
degrees – Skew angle.
-
void gui_img_set_opacity(gui_img_t *_this, unsigned char opacity_value)
-
Set the opacity of the image.
- 参数:
this – The image widget pointer.
opacity_value – Opacity value (0-255, default 255).
-
void gui_img_set_focus(gui_img_t *_this, float c_x, float c_y)
-
Set the focus point for image transformations.
- 参数:
this – The image widget pointer.
c_x – Center X coordinate.
c_y – Center Y coordinate.
-
gui_img_t *gui_img_create_from_mem(void *parent, const char *name, void *addr, int16_t x, int16_t y, int16_t w, int16_t h)
-
Create an image widget from memory address.
备注
Create an image widget and set attribute.
- 参数:
parent – The father widget it nested in.
name – Widget name.
addr – The bin file address.
x – The X-axis coordinate of the widget.
y – The Y-axis coordinate of the widget.
w – The width of the widget.
h – The height of the widget.
- 返回:
-
The widget object pointer.
-
gui_img_t *gui_img_create_from_ftl(void *parent, const char *name, void *ftl, int16_t x, int16_t y, int16_t w, int16_t h)
-
Create an image widget from memory address.
备注
Create an image widget and set attribute.
- 参数:
parent – The father widget it nested in.
name – Widget name.
ftl – Not xip address, use ftl address.
x – The X-axis coordinate of the widget.
y – The Y-axis coordinate of the widget.
w – The width of the widget.
h – The height of the widget.
- 返回:
-
Return the widget object pointer.
-
gui_img_t *gui_img_create_from_fs(void *parent, const char *name, void *file, int16_t x, int16_t y, int16_t w, int16_t h)
-
Create an image widget from filesystem.
- 参数:
parent – The father widget it nested in.
name – Image widget name.
file – Image file path.
x – The X-axis coordinate of the widget.
y – The Y-axis coordinate of the widget.
w – The width of the widget.
h – The height of the widget.
- 返回:
-
gui_img_t*.
-
void gui_img_set_quality(gui_img_t *_this, bool high_quality)
-
Set the image’s quality.
- 参数:
this – The image widget pointer.
high_quality – True for high quality rendering, false otherwise.
-
void gui_img_tree_convert_to_img(gui_obj_t *obj, gui_matrix_t *matrix, uint8_t *shot_buf)
-
Convert a tree to an image data.
- 参数:
obj – Tree root.
matrix – Null if no need to transform.
shot_buf – Buffer for the screenshot.
-
float gui_img_get_scale_x(gui_img_t *_this)
-
Get the scale factor in X direction.
- 参数:
-
this – The image widget pointer.
- 返回:
-
Scale factor in X direction.
-
float gui_img_get_scale_y(gui_img_t *_this)
-
Get the scale factor in Y direction.
- 参数:
-
this – The image widget pointer.
- 返回:
-
Scale factor in Y direction.
-
float gui_img_get_degrees(gui_img_t *_this)
-
Get the rotation angle in degrees.
- 参数:
-
this – The image widget pointer.
- 返回:
-
Rotation angle in degrees.
-
float gui_img_get_c_x(gui_img_t *_this)
-
Get the center X coordinate for transformations.
- 参数:
-
this – The image widget pointer.
- 返回:
-
Center X coordinate.
-
float gui_img_get_c_y(gui_img_t *_this)
-
Get the center Y coordinate for transformations.
- 参数:
-
this – The image widget pointer.
- 返回:
-
Center Y coordinate.
-
float gui_img_get_t_x(gui_img_t *_this)
-
Get the translation in X direction.
- 参数:
-
this – The image widget pointer.
- 返回:
-
Translation in X direction.
-
float gui_img_get_t_y(gui_img_t *_this)
-
Get the translation in Y direction.
- 参数:
-
this – The image widget pointer.
- 返回:
-
Translation in Y direction.
-
void gui_img_set_image_data(gui_img_t *_this, const uint8_t *image_data_pointer)
-
Sets the image data for a specified image widget.
This function assigns the given image data to the specified image widget. The image data might correspond to various formats, and the format should be compatible with the handling of
gui_img_t
.- 参数:
widget – The pointer to the image widget (
gui_img_t
) for which the image data is to be set.image_data_pointer – The pointer to the image data to be set to the widget. The data should persist as long as the widget needs it or until it is explicitly updated.
-
const uint8_t *gui_img_get_image_data(gui_img_t *_this)
-
Gets the image data from a specified image widget.
This function returns the current image data that is set in the specified image widget.
- 参数:
-
widget – The pointer to the image widget (
gui_img_t
) from which the image data should be retrieved. - 返回:
-
A pointer to the image data currently set in the widget. If no image data is set, the result may be
NULL
.
-
struct gui_img_t
-
Image widget structure.
Public Members
-
gui_obj_t base
-
draw_img_t *draw_img
-
float degrees
-
float scale_x
-
float scale_y
-
float f_x
-
float f_y
-
float t_x
-
float t_y
-
void *data
-
void *filename
-
void *ftl
- union gui_img_t
-
gd_GIF *gif
-
uint32_t opacity_value
-
uint32_t blend_mode
-
uint32_t storage_type
-
uint32_t high_quality
-
uint32_t need_clip
-
uint32_t gif_flag
-
uint8_t checksum
-
uint8_t animate_array_length
-
gui_obj_t base