class Image —— 显示图像。

Image 是用于显示图像的基本对象类型。

MicroPython 应用示例:

 1# SPDX-FileCopyrightText: 2024 M5Stack Technology CO LTD
 2#
 3# SPDX-License-Identifier: MIT
 4
 5import os, sys, io
 6import M5
 7from M5 import *
 8
 9
10image0 = None
11title0 = None
12
13
14def setup():
15    global image0, title0
16
17    M5.begin()
18    Widgets.fillScreen(0x222222)
19    image0 = Widgets.Image("res/img/SCR-20240902-itcy.png", 71, 64)
20    title0 = Widgets.Title("Image CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
21
22    image0.setImage("res/img/default.png")
23    image0.setImage("res/img/SCR-20240902-itcy.png")
24    image0.setCursor(x=0, y=0)
25    image0.setVisible(True)
26
27
28def loop():
29    global image0, title0
30    M5.update()
31
32
33if __name__ == "__main__":
34    try:
35        setup()
36        while True:
37            loop()
38    except (Exception, KeyboardInterrupt) as e:
39        try:
40            from utility import print_error_msg
41
42            print_error_msg(e)
43        except ImportError:
44            print("please update to latest firmware")

UiFlow2 应用示例

example.png

image_cores3_example.m5f2

Constructors

class Widgets.Image(str: file, x: int, y: int, parent)

创建一个 Image 对象。它接受以下参数:

  • file 是要显示的图像文件路径。支持的格式包括 BMP、JPG 和 PNG。

  • x 是显示图像的起始 X 轴坐标。

  • y 为起始 Y 轴坐标,图像将显示在该位置。

  • parent 是绘制图像的图形对象。如果未提供,则使用默认显示屏。

Methods

Image.setCursor(x: int, y: int)

设置 Imgae 对象的位置。接受以下参数:

  • x 为显示的起始 X 轴坐标。

  • y 是显示的起始 Y 轴坐标。

UiFlow2

setCursor.png

Image.setImage(str: file)

设置要显示的图像。

  • file 是要显示的新图像文件的路径。

UiFlow2

setImage.png

setImage1.png

Image.setVisible(visible: bool)

设置 Imgae 对象的可见性。接受以下参数:

  • visible 是显示图像的可见性。

UiFlow2

setVisible.png