Skip to content

Icon

Create an image loaded from a file.

Creating an Icon

You can create an Icon using the following functions:

Icon(filename)
Icon(filename, width, height, rotation, visibility)
Parameter Type Default Description
filename str required The image file to load, ending in ".jpg" or ".png".
width int or float None The width to scale the image to, in pixels. Defaults to the image's own width.
height int or float None The height to scale the image to, in pixels. Defaults to the image's own height.
backgroundColor Color None The color of the background behind the image. Defaults to Color.CLEAR (no background).
fill bool True Whether the background is filled in (True) or just an outline (False).
thickness int or float 0 The background's outline thickness, in pixels.
rotation int or float 0 How far to turn the image, in degrees, counter-clockwise.
visibility int 100 How visible the image is, from 0 (invisible) to 100 (fully visible).

For example,

icon = Icon("mona-lisa.jpg")

Once created, you can add it to a Display using the Display's add() function.

Functions

Once an Icon has been created, the following functions are available:

Function Description
getPixel(column, row) Return the color of one pixel.
setPixel(column, row, color) Set the color of one pixel.
getPixels() Return every pixel in the image.
setPixels(pixels) Replace every pixel in the image.
getBackgroundColor() Return the icon's background color.
setBackgroundColor() Set the icon's background color.
crop(x, y, width, height) Crop the image to a rectangular region.
save(filename) Save the image to a JPG or PNG file.

Additionally, the following common functions are available: