CANVAS:draw image

CANVAS:draw_image(name, attrs)

Draw an image within the canvas directed by the user specified properties.

Parameters:

name

The project relative name of the image, same as used in the Image

attrs

A table of properties containing information about how to draw the image.

This table can contain the following optional keys:

x

The x position of the upper left corner of the text (default: 0)

y

The y position of the upper left corner of the text (default: 0)

w

The width to scale the image to (default: natural width)

h

The height to scale the image to (default: natural height)

rotation

The angle of rotation in degrees (default: 0). This rotation point is around the upper left corner of the image.

halign

The horizontal anchor, gre.LEFT, gre.CENTER, or gre.RIGHT (default: gre.LEFT)

valign

The vertical anchor, gre.TOP, gre.CENTER, or gre.BOTTOM (default: gre.TOP)

Example:

-- Draw an image scaled to the canvas size
function DrawImage(name)
    local canvas = gre.get_canvas(name)
    local size = canvas:get_dimensions()
    local attrs = {}
    attrs.w = size.width
    attrs.h = size.height
    canvas:draw_image("images/logo.png", attrs)
end
Was this article helpful?
0 out of 0 found this helpful