Simple Image
The simple img widget is a simplified version of the img widget, lacking transformation operations such as rotation, translation, and scaling.
Usage
Create Widget
Use gui_simple_img_create()
to create a simple image widget. If src_mode_type
is IMG_SRC_MEMADDR
, the image will be loaded from a memory address; if src_mode_type
is IMG_SRC_FILESYS
, the image will be loaded from the file system, with addr
being the path to the image. Refer to the following enumeration for loading methods:
typedef enum
{
IMG_SRC_MEMADDR = 0,
IMG_SRC_FILESYS,
IMG_SRC_FTL,
} IMG_SOURCE_MODE_TYPE;
Set Location
If you need to update the location of image widget, use gui_simple_img_set_location()
to relocate.
x, y
is the new coordinate.
Set Attribute
You can use gui_simple_img_set_attribute()
to set the attribute of an image widget, replace it with a new image and set a new coordinate.
Get Height/Width
If you want to get the height/width of image widget, you can do so with gui_simple_img_get_height()
or gui_simple_img_get_width()
.
Example
#include "root_image_hongkong/ui_resource.h"
#include "gui_simple_img.h"
#include "gui_text.h"
#include "draw_font.h"
char *tb1_text = "gui_simple_img_create";
void page_tb1(void *parent)
{
static char array1[50];
static char array2[50];
gui_font_mem_init(ARIALBD_SIZE16_BITS4_FONT_BIN);
gui_simple_img_t *img_test = gui_simple_img_create(parent, "simg", SET_ON_BIN, 0, 0, 0, 0, 0);
gui_text_t *text1 = gui_text_create(parent, "text1", 10, 100, 300, 30);
gui_text_set(text1, tb1_text, GUI_FONT_SRC_BMP, APP_COLOR_WHITE, strlen(tb1_text), 16);
gui_text_mode_set(text1, LEFT);
gui_text_t *text2 = gui_text_create(parent, "text2", 10, 130, 330, 30);
gui_text_set(text2, tb1_text, GUI_FONT_SRC_BMP, APP_COLOR_WHITE, strlen(tb1_text), 16);
gui_text_mode_set(text2, LEFT);
sprintf(array1, "gui_img_get_height %d", gui_simple_img_get_height(img_test));
text2->content = array1;
text2->len = strlen(array1);
gui_text_t *text3 = gui_text_create(parent, "text3", 10, 160, 330, 30);
gui_text_set(text3, tb1_text, GUI_FONT_SRC_BMP, APP_COLOR_WHITE, strlen(tb1_text), 16);
gui_text_mode_set(text3, LEFT);
sprintf(array2, "gui_img_get_width %d", gui_simple_img_get_width(img_test));
text3->content = array2;
text3->len = strlen(array2);
}
void page_tb2(void *parent)
{
gui_simple_img_t *img_test = gui_simple_img_create(parent, "simg", SET_ON_BIN, 0, 0, 0, 0, 0);
gui_simple_img_set_location(img_test, 50, 50);
gui_text_t *text2 = gui_text_create(parent, "text2", 10, 150, 330, 24);
gui_text_set(text2, "gui_simple_img_set_location", GUI_FONT_SRC_BMP, APP_COLOR_WHITE, 27, 16);
gui_text_mode_set(text2, LEFT);
}
void page_tb3(void *parent)
{
gui_simple_img_t *img_test = gui_simple_img_create(parent, "simg", SET_ON_BIN, 0, 0, 0, 0, 0);
gui_simple_img_set_attribute(img_test, "test", SET_OFF_BIN, 20, 20);
gui_text_t *text3 = gui_text_create(parent, "text3", 10, 120, 330, 24);
gui_text_set(text3, "gui_simple_img_set_attribute", GUI_FONT_SRC_BMP, APP_COLOR_WHITE, 28, 16);
gui_text_mode_set(text3, LEFT);
}

API
Functions
-
uint16_t gui_simple_img_get_width(gui_simple_img_t *this)
-
Load the image to read its width.
- Parameters:
-
img – The image widget pointer.
- Returns:
-
uint16_t Image’s width.
-
uint16_t gui_simple_img_get_height(gui_simple_img_t *this)
-
Load the image to read its height.
- Parameters:
-
img – The image widget pointer.
- Returns:
-
uint16_t Image’s height.
-
void gui_simple_img_set_location(gui_simple_img_t *this, uint16_t x, uint16_t y)
-
Set the image’s location.
- Parameters:
img – The image widget pointer.
x – The x coordinate.
y – The y coordinate.
-
void gui_simple_img_set_mode(gui_simple_img_t *this, BLEND_MODE_TYPE mode)
-
Set the image’s blend mode.
- Parameters:
img – The image widget pointer.
mode – The enumeration value of the mode is BLEND_MODE_TYPE.
-
void gui_simple_img_set_attribute(gui_simple_img_t *this, const char *name, void *addr, int16_t x, int16_t y)
-
Set x, y and file path.
- Parameters:
img – Image widget.
name – Change widget name.
addr – Change picture address.
x – X-axis coordinate.
y – Y-axis coordinate.
-
void gui_simple_img_set_opacity(gui_simple_img_t *this, unsigned char opacity_value)
-
Add opacity value to the image.
- Parameters:
this – The image widget pointer.
opacity_value – The opacity value ranges from 0 to 255, default 255.
-
void gui_simple_img_set_quality(gui_simple_img_t *this, bool high_quality)
-
Set the image’s quality.
- Parameters:
img – The image widget pointer.
high_quality – Image drawn in high quality or not.
-
gui_simple_img_t *gui_simple_img_create(void *parent, const char *name, void *addr, int16_t x, int16_t y, int16_t w, int16_t h, IMG_SOURCE_MODE_TYPE src_mode_type)
-
Create a simple image widget.
Note
Create a simple image widget and set attribute.
- Parameters:
parent – The father widget it nested in.
name – Widget name.
addr – Bin file address in IMG_SRC_MEMADDR, or image file path in IMG_SRC_FILESYS mode.
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.
src_mode_type – The type of image source.
- Returns:
-
Return the widget object pointer.
-
struct gui_simple_img_t
-
Image widget structure.
Public Members
-
gui_obj_t base
-
draw_img_t *draw_img
-
void *data
-
void *filename
-
void *ftl
- union gui_simple_img_t
-
uint32_t opacity_value
-
uint32_t blend_mode
-
uint32_t src_mode
-
uint32_t high_quality
-
uint32_t press_flag
-
press to change picture to the highlighted
-
uint32_t release_flag
-
uint8_t checksum
-
gui_obj_t base