“””M5Image”””
M5Image 是一个可在用户界面中显示图像的控件。
UiFlow2 示例
显示图像
在 UiFlow2 中打开 cores3_show_image_example.m5f2 项目。
该示例演示如何在屏幕上显示图像。
UiFlow2 代码块:
示例输出:
None
MicroPython 示例
显示图像
该示例演示如何在屏幕上显示图像。
MicroPython 代码块:
1# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD 2# 3# SPDX-License-Identifier: MIT 4 5import os, sys, io 6import M5 7from M5 import * 8import m5ui 9import lvgl as lv 10 11 12page0 = None 13image0 = None 14image1 = None 15 16 17def setup(): 18 global page0, image0, image1 19 20 M5.begin() 21 Widgets.setRotation(1) 22 m5ui.init() 23 page0 = m5ui.M5Page(bg_c=0xFFFFFF) 24 image0 = m5ui.M5Image("/flash/res/img/uiflow.jpg", x=129, y=54, parent=page0) 25 image1 = m5ui.M5Image("/flash/res/img/uiflow.png", x=129, y=118, parent=page0) 26 27 page0.screen_load() 28 image0.set_image("/flash/res/img/uiflow.jpg") 29 image1.set_image("/flash/res/img/uiflow.png") 30 31 32def loop(): 33 global page0, image0, image1 34 M5.update() 35 36 37if __name__ == "__main__": 38 try: 39 setup() 40 while True: 41 loop() 42 except (Exception, KeyboardInterrupt) as e: 43 try: 44 m5ui.deinit() 45 from utility import print_error_msg 46 47 print_error_msg(e) 48 except ImportError: 49 print("please update to latest firmware")
示例输出:
None
API参考
“””M5Image”””
- class m5ui.image.M5Image(*args, **kwargs)
基类:
image创建一个图像对象。
- 参数:
MicroPython 代码块:
from m5ui import M5Image import lvgl as lv m5ui.init() image_0 = M5Image("/flash/res/img/defalut.jpg", x=10, y=10, parent=page0) image_1 = M5Image("/flash/res/img/uiflow.jpg", x=50, y=50, parent=page0)
- set_flag(flag, value)
在对象上设置标志。若
value为 True,则添加该标志;为 False 则移除。UiFlow2 代码块:

MicroPython 代码块:
image_0.set_flag(lv.obj.FLAG.HIDDEN, True)
- set_pos(x, y)
设置图像的位置。
UiFlow2 代码块:

MicroPython 代码块:
image_0.set_pos(100, 100)
- align_to(obj, align, x, y)
将图像对齐到另一个对象。
UiFlow2 代码块:

MicroPython 代码块:
image_0.align_to(page_0, lv.ALIGN.CENTER, 0, 0)
- set_image(path)
设置要显示的图像。
- 参数:
path (str) – 图像文件的路径。
UiFlow2 代码块:

MicroPython 代码块:
image_0.set_image("/flash/res/img/uiflow.jpg") image_1.set_image("/sd/uiflow.png")




