Image:draw(x, y, [ ratio ], [ opacity ] ) method
Draws the Image on its Canvas, at the specified position
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)
[ ratio ]
An optional number
that represent a ratio to apply to to the Image width and height. The default value is 1, meaning that the original ratio will be used
[ 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:draw() 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:draw(math.random(w)-80, math.random(h), math.random(), math.random())
self:flip()
end
ui.run(win):wait()