STB 图像


STB图像控件是用于显示图像的基本控件。可以设置左、中、右三种图像,中间的图像将会重复以匹配对象的宽度,STB图像控件支持 bmp、jpg、png、gif 等格式。

在 STB 图像库中,STB 并不是一个缩写,而是一个命名惯例,用于标识由 Sean T. Barrett 开发的一系列单文件库。STB 图像库(stb_image.h) 是其中之一,用于加载和存储多种常见的图像格式。

用法

创建控件

使用gui_img_stb_create_from_mem(void *parent, const char *name, void *addr, uint32_t size, uint8_t type, int16_t x, int16_t y); 从内存中创建一个STB图像控件,注意需要确保类型和大小是正确的。

设置属性

使用 gui_img_stb_set_attribute(gui_stb_img_t *img, void *addr, uint32_t size, uint8_t type, int16_t x, int16_t y); 来设置STB图像控件的属性,可以设置新的文件和新的坐标。

示例

code
#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);
}


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)

Creat a image widget with buffer.

备注

This widget is use to display image which needs to decode.

备注

The data of image can be static char or data transformed by BLE.

参数:
  • parent – The father widget which the scroll text nested in.

  • name – The widget’s name.

  • addr – The data address of image.

  • size – The data size of image.The unit is bytes.

  • input_type – The input type of image. bmp 11, jpeg 12, png 13,

  • output_type – The output type of image. RGB565 RGB888,

  • x – The X-axis coordinate of the text box.

  • x – 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
#include <gui_img_stb.h>

stb img widget gif information structure

Public Members

uint32_t init_time_ms
uint32_t *delay_ms
uint32_t cycle_index
uint32_t delay_ms_sum
uint32_t total_frame
uint32_t current_frame
struct gui_stb_img_t
#include <gui_img_stb.h>

stb img widget information structure

Public Members

gui_obj_t base
gui_img_t *img
bool src_changed
GUI_FormatType input_format
GUI_FormatType output_format
void *data_buffer
uint32_t data_length
gui_gif_info_t *gif_info
int16_t offset_x
int16_t offset_y
struct IODEV
#include <gui_img_stb.h>

Public Members

uint8_t *data
uint32_t size
uint32_t index
uint8_t *fbuf
uint8_t *image