Image (ls_image_t)

Draws a converted image descriptor, optionally rotated around a pivot. An A8 source is a mask you tint, so one asset serves any color.

ls_image.hSource header · lvgl/lvgl_safe
 
ls_error_code_t ls_image_create(ls_screen_t * screen, ls_image_t * image);

Pixel data is described by an ls_image_dsc_t, which is what the image converter generates for you (see Assets):

 
typedef struct {
    ls_frame_buffer_color_t color_format;  /* one of ls_image_color_format_t */
    int32_t width;
    int32_t height;
    int32_t stride;                        /* bytes per row */
    const void * data;                     /* pixel data */
} ls_image_dsc_t;

Supported formats (ls_image_color_format_t):

FormatUse it for
LS_IMAGE_COLOR_FORMAT_RGB565Opaque 16-bit images - cheapest to blit
LS_IMAGE_COLOR_FORMAT_ARGB8888Full color with per-pixel alpha
LS_IMAGE_COLOR_FORMAT_A8An alpha-only mask tinted with the widget's a8_color - one asset, any color

Note: RGB888 and RGB565 image sources are not yet supported in the preview. Use ARGB8888 or A8.

FieldTypeDescription
x, yuint32_tTop-left position
srcconst ls_image_dsc_t *Image source descriptor
opauint8_tOpacity (0..255)
a8_colorls_color_tTint color, used only for A8 sources
pivot_x, pivot_yint32_tRotation pivot, relative to the image's top-left
rotationint32_tRotation angle in degrees

There is no width/height: the size comes from src.

Defaults after create: opaque, no rotation, black a8_color, src is NULL. An image without a src makes ls_render() fail for the whole frame.

 
extern const ls_image_dsc_t my_logo;   /*generated by the image converter*/

static ls_image_t logo;

if(ls_image_create(&screen, &logo) != LS_ERROR_CODE_OK) return 1;
logo.x = 20;
logo.y = 20;
logo.src = &my_logo;                   /*without a src, ls_render() fails*/

/*An A8 source is a mask: one asset, tinted to whatever color you want.*/
extern const ls_image_dsc_t my_icon_a8;

static ls_image_t needle;

if(ls_image_create(&screen, &needle) != LS_ERROR_CODE_OK) return 1;
needle.x = 200;
needle.y = 20;
needle.src = &my_icon_a8;
needle.a8_color = LS_COLOR_HEX(0x3d8bfd);
needle.pivot_x = 16;                   /*relative to the image's top-left*/
needle.pivot_y = 16;
needle.rotation = 45;

Last updated on