STB 图像 (STB Img)
STB图像控件是用于显示图像的基本控件。可以设置左、中、右三种图像,中间的图像将会重复以匹配对象的宽度,STB图像控件支持 bmp、jpg、png、gif 等格式。
在 STB 图像库中,STB 并不是一个缩写,而是一个命名惯例,用于标识由 Sean T. Barrett 开发的一系列单文件库。STB 图像库 stb_image.h
是其中之一,用于加载和存储多种常见的图像格式。
用法
创建控件
使用 gui_img_stb_create_from_mem()
从内存中创建一个STB图像控件,注意需要确保类型和大小是正确的。
设置属性
使用 gui_img_stb_set_attribute()
来设置STB图像控件的属性,可以设置新的文件和新的坐标。
示例
#include "root_image_hongkong/ui_resource.h"
#include "gui_obj.h"
#include "gui_app.h"
#include "gui_img.h"
#include "gui_img_stb.h"
static void app_home_ui_design(gui_app_t *app)
{
gui_stb_img_t *jpg = gui_img_stb_create_from_mem(&app->screen, "jpg", TEST_JPG, 0x6640, JPEG, 0, 0);
gui_stb_img_t *png = gui_img_stb_create_from_mem(&app->screen, "png", TEST_PNG, 0x2B00, PNG, 170, 170);
}

STB图像示例
API
Functions
-
void gui_img_stb_set_attribute(gui_stb_img_t *this, void *addr, uint32_t size, GUI_FormatType type, int16_t x, int16_t y)
-
Set stb image widget attribute.
- 参数:
this – stb image widget.
addr – Image address.
size – Image file size by Byte.
type – Image type.
x – X-axis coordinate.
y – Y-axis coordinate.
-
void gui_img_stb_set_attribute_static(gui_stb_img_t *this, void *addr, uint32_t size, GUI_FormatType type, int16_t x, int16_t y)
-
Set stb image widget attribute without free rgb data.
- 参数:
this – stb image widget.
addr – Image address.
size – Image file size by Byte.
type – Image type.
x – X-axis coordinate.
y – Y-axis coordinate.
-
gui_stb_img_t *gui_img_stb_create_from_mem(void *parent, const char *name, void *addr, uint32_t size, GUI_FormatType input_type, GUI_FormatType output_type, int16_t x, int16_t y)
-
Create an image widget with buffer.
备注
This widget is used to display an image that needs decoding.
备注
The data of the image can be static char or data transformed by BLE.
- 参数:
parent – The parent widget in which the scroll text is nested.
name – The widget’s name.
addr – The data address of the image.
size – The data size of the image. The unit is bytes.
input_type – The input type of the image. bmp 11, jpeg 12, png 13.
output_type – The output type of the image. RGB565 RGB888.
x – The X-axis coordinate of the text box.
y – The Y-axis coordinate of the text box.
- 返回:
-
gui_stb_img_t*
-
void gui_img_stb_set_output_format(gui_stb_img_t *this, GUI_FormatType output)
-
Set output format.
备注
RGB565 or RGB888.
- 参数:
this – stb image widget.
output – Output format.
-
struct gui_gif_info_t
-
stb img widget gif information structure
-
struct gui_stb_img_t
-
stb img widget information structure
-
struct IODEV