class ImagePlus – display remote image
The ImagePlus class extends the Widgets.Image class to provide additional functionalities for handling images with dynamic updates.
Micropython Example:
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:
Constructors
- class Widgets.ImagePlus(url, x, y, enable, period, default_img='res/img/default.jpg', parent=None)
Create an ImagePlus object. It accepts the following parameters:
url
is the URL of the image to be fetched and displayed.x
is the starting X-axis coordinate where the image will be displayed.y
is the starting Y-axis coordinate where the image will be displayed.enable
is a boolean indicating whether periodic updates of the image are enabled.period
is the update period in milliseconds when enable is True.default_img
is the path to the default image file to be displayed if the URL fetch fails. Supported formats are BMP, JPG, and PNG. Default is “res/img/default.jpg”.parent
is the graphical object on which the image will be drawn. If not provided, the default display will be used.
Methods
- ImagePlus.set_update_enable(enable: bool)
Enable or disable periodic updates of the image. Accept the following parameters:
enable
is a boolean indicating whether updates should be enabled.
UIFLOW2:
- ImagePlus.set_update_period(period: int)
Set the update period for fetching and displaying the image. Accept the following parameters:
period
is the update period in milliseconds.
UIFLOW2:
- ImagePlus.setCursor(x: int, y: int)
Set the position of the ImagePlus object. Accept the following parameters:
x
is the starting X-axis coordinate displayed.y
is the starting Y-axis coordinate displayed.
UIFLOW2: