Image:drawrect(x, y, width, height, [opacity], [interpolation] ) method


Draws the Image on its Canvas, using the specified position, width, height and opacity.

Parameters

x

A number representing the horizontal position (zero means the left side of the Canvas)

y

A number representing the vertical position (zero means the top side of the Canvas)

width

A number that represent the Image width

height

A number that represent the Image height

[opacity]

An optional number representing the degree of opacity, defaulting to 1 (full opacity). A value of 0.5 means middle transparency

[interpolation]

An optional string used to specify the quality of image scaling :

  • "nearest" : Use the exact color of the nearest bitmap pixel to the current rendering pixel (the default).
  • "linear" : Uses a four point sample and linear interpolation, using more processing time, but outputs a higher quality image.

Return value

This function returns no value.

Example

local ui = require "ui" require "canvas" -- create a simple Window local win = ui.Window("Image:drawrect sample", "fixed", 500, 400) -- create a Canvas local canvas = ui.Canvas(win) canvas.align = "all" canvas.bgcolor = 0x000000FF local w = canvas.width local h = canvas.height local img = canvas:Image("LuaRT.png") function canvas:onPaint() self:begin() img:drawrect(math.random(w), math.random(h), math.random(500), math.random(400), math.random(), math.random()) self:flip() end ui.run(win):wait()