Image#

class UI.Image()#

A picture, or a plain colored rectangle. Added to a UI.Canvas or a UI.Panel.

Base class: UI.Object
Image.getContent()#
Image.setContent(value)#

The picture to show, as the contents of a PNG or JPEG file. Set it to an empty array to show a plain rectangle instead.

Property:

Can be read or written

Return type:

Uint8Array

Note

Reading this returns what was last set, not what is on the screen, and returns an empty array if no picture has been set. A picture drawn with UI.Image.setPixels() is not returned here either.

Image.setPixels(data, width, height)#

Draw the picture from raw pixels rather than a file, so that a client can draw whatever it likes, a graph for instance, and redraw it as often as it likes.

Arguments:
  • data (Uint8Array) – The pixels, 4 bytes per pixel: red, green, blue and alpha, each 0 to 255. Pixels run left to right and rows run top to bottom, the way image files store them, so the array must hold width times height times 4 bytes.

  • width (number) – How many pixels wide the picture is.

  • height (number) – How many pixels tall the picture is.

Note

Redrawing at an unchanged size draws into the picture already there, so a picture redrawn every update does not build a new one each time.

Image.updatePixels(data, x, y, width, height)#

Redraw part of a picture drawn with UI.Image.setPixels(): a block of the given size, with its top left corner x pixels in from the left edge and y pixels down from the top. The rest of the picture is left as it is, so a change to a small part of a large picture, one new column of a scrolling graph for instance, only sends the part that changed.

Arguments:
  • data (Uint8Array) – The pixels of the block, laid out as for UI.Image.setPixels(): 4 bytes per pixel, rows top to bottom, width times height times 4 bytes in all.

  • x (number) – How many pixels the block sits in from the left edge.

  • y (number) – How many pixels the block sits down from the top.

  • width (number) – How many pixels wide the block is.

  • height (number) – How many pixels tall the block is.

Note

The image must already be showing a picture drawn from raw pixels, which is what sets the size, and the block must fit inside it. A picture loaded from a file cannot be redrawn this way: the file contents a client reads back would no longer be what is on the screen.

Image.getColor()#
Image.setColor(value)#

The color the image is tinted with, or the color of the rectangle when no picture is set.

Property:

Can be read or written

Return type:

StdLib.ColorRGBA