class ImagePlus —— 显示远程图像

ImagePlus 类继承自 Widgets.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 *
 8from image_plus import ImagePlus
 9
10
11title0 = None
12image_plus0 = None
13
14
15def setup():
16    global title0, image_plus0
17
18    M5.begin()
19    Widgets.fillScreen(0x222222)
20    title0 = Widgets.Title("Image+ CoreS3 Example", 3, 0xFFFFFF, 0x0000FF, Widgets.FONTS.DejaVu18)
21    image_plus0 = ImagePlus(
22        "https://static-cdn.m5stack.com/resource/public/assets/aboutus/m5logo2022.png",
23        43,
24        51,
25        True,
26        3000,
27        default_img="res/img/default.png",
28    )
29
30    image_plus0.setVisible(True)
31    image_plus0.set_update_period(5000)
32    image_plus0.set_update_enable(True)
33
34
35def loop():
36    global title0, image_plus0
37    M5.update()
38
39
40if __name__ == "__main__":
41    try:
42        setup()
43        while True:
44            loop()
45    except (Exception, KeyboardInterrupt) as e:
46        try:
47            from utility import print_error_msg
48
49            print_error_msg(e)
50        except ImportError:
51            print("please update to latest firmware")

UiFlow2 应用示例

example.png

imageplus_cores3_example.m5f2

Constructors

class Widgets.ImagePlus(url, x, y, enable, period, default_img='res/img/default.jpg', parent=None)

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

  • url 是要获取并显示的图像的 URL。

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

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

  • enable 是一个布尔值,用于指示是否启用图像的定期更新。

  • period 是当 enableTrue 时的更新周期,单位为毫秒。

  • default_img 是默认图片文件的路径,当 URL 获取失败时将显示该图片。支持的格式为 BMP、JPG 和 PNG。默认值为 “res/img/default.jpg”

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

Methods

ImagePlus.set_update_enable(enable: bool)

启用或禁用图像的周期性更新。接受以下参数:

  • enable 是一个布尔值,用于指示是否应启用更新。

UIFLOW2:

set_update_enable.png

ImagePlus.set_update_period(period: int)

设置用于获取并显示图像的更新周期。接受以下参数:

  • period 为更新周期,单位为毫秒。

UIFLOW2:

set_update_period.png

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

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

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

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

UIFLOW2:

setCursor.png

ImagePlus.setVisible(visible: bool)

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

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

UIFLOW2:

setVisible.png

ImagePlus.is_valid_image() bool

检查获取的图像是否有效。如果图像有效则返回 True,否则返回 False

UIFLOW2:

is_valid_image.png