STB Img

The image widget is the basic widget used to display an image. You can set left, right, and center images, and the center image will be repeated to match the width of the object. STB image widgets support bmp, jpg, png, gif, etc.

In the STB image library, STB is not an acronym. It is actually a naming convention used to identify a series of single-file libraries developed by Sean T. Barrett. The STB image library stb_image.h is one of these libraries and is used to load and store various common image formats.

Usage

Create Widget

You can use gui_img_stb_create_from_mem() to create an STB image widget from memory. Please confirm that the type and size are correct.

Set Attribute

You can use gui_img_stb_set_attribute() to set the attribute of an STB image widget, replace it with a new file and set a new coordinate.

Example

#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);
}
https://foruda.gitee.com/images/1703146027234656357/48137b9c_9325830.png

STB Image Example

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.

Parameters:
  • 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.

Parameters:
  • 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.

Note

This widget is used to display an image that needs decoding.

Note

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

Parameters:
  • 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.

Returns:

gui_stb_img_t*

void gui_img_stb_set_output_format(gui_stb_img_t *this, GUI_FormatType output)

Set output format.

Note

RGB565 or RGB888.

Parameters:
  • this – stb image widget.

  • output – Output format.

struct gui_gif_info_t

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

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

Public Members

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