Canvas:Image(file) method


Creates an Image object instance, which content is loaded from a file.

Parameters

file

A File or a filename as a string representing the file to load the image from.

The canvas module support the following file types :
  • BMP (Windows Bitmap Format) *.bmp
  • GIF (Graphics Interchange Format 89a) *.gif(not animated, first frame only)
  • ICO (Icon Format) *.ico
  • JPEG (Joint Photographic Experts Group) *.jpg | *.jpeg
  • PNG (Portable Network Graphics) *.png
  • TIFF (Tagged Image File Format) *.tiff | *.tif
  • Windows Media Photo *.wmp
  • DDS (DirectDraw Surface) *.dds

Return value

This function returns an Image instance.

Example

local ui = require "ui" require "canvas" -- create a simple Window local win = ui.Window("Canvas.Image() sample", "fixed", 320, 200) -- create a Canvas local canvas = ui.Canvas(win) canvas.align = "all" local img = canvas:Image("LuaRT.png") local xpos = -img.width function canvas:onPaint() self:clear() img:draw(xpos, 30) xpos = xpos > canvas.width and -img.width or xpos+6 end win:show() -- update user interface repeat ui.update() until not win.visible