Image:drawsub(x, y, subx, suby, subwidth, subheight, [opacity], [interpolation]) method


Draws a sub part of the Image on the Canvas.

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)

subx, suby

Numbers that represent upper left corner position of the sub part in the Image.

subwidth, subheight

Numbers that represent the size of the sub part in the Image.

[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:drawsub 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:drawsub(math.random(w), math.random(h), math.random(500), math.random(400), math.random(), math.random()) self:flip() end ui.run(win):wait()