class Image – display image
Image is the basic object type used to display images.
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 * 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:
Constructors
- class Widgets.Image(str: file, x: int, y: int, parent)
Create an Image object. It accepts the following parameters:
file
is the path to the image file to be displayed. Supported formats are BMP, JPG, and PNG.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.parent
is the graphical object on which the image will be drawn. If not provided, the default display will be used.
Methods
- Image.setCursor(x: int, y: int)
Set the position of the Imgae object. Accept the following parameters:
x
is the starting X-axis coordinate displayed.y
is the starting Y-axis coordinate displayed.
UIFLOW2:
- Image.setImage(str: file)
Set the image to be displayed.
file
is the path to the new image file to be displayed.
UIFLOW2: