Picture:load(File | filename, [width], [height]) method


Change the Picture image by loading it from a file on disk.

Parameters

File | filename

A File object or a filename string, representing the image file whose content will be loaded.

[width]

An optional number indicating the new width of the Picture widget, defaulting to the image width.

[height]

An optional number indicating the new height of the Picture widget, defaulting to the image height.

Return value

This function returns true if the image loading succeeded, or false otherwise.

Example

local ui = require "ui" local win = ui.Window("Picture.load() and save() example", 512, 380) -- create an empty Picture object local img = ui.Picture(win, "") -- load the image from disk img:load(sys.File(arg[0]).path.."\\LuaRT.png") -- center the Picture on the window img:center() -- create a button local button = ui.Button(win, "Save picture to...") button:center() button.y = img.y + img.height + 30 -- button onClick event handler function button:onClick() local file = ui.savedialog("Save picture as...", false, "All files (*.*)|*.*|PNG image files (*.png)|*.png|JPEG image files (*.jpg)|*.jpg|Bitmap image files (*.bmp)|*.bmp|GIF image files (*.gif)|*.gif|ICO image files (*.ico)|*.ico|TIFF image files (*.tiff)|*.tiff") if file ~= nil and (not file.exists or (file.exists and ui.confirm(file.fullpath.." already exists. Continue and overwrite its content ?") == "yes")) then if img:save(file) then win:status("Picture saved as "..file.fullpath) end end end win:center() win:show() repeat ui.update() until win.visible == false