Skip to main content

Decode a QR code image (:qr_decode)

Declaration

text = img:qr_decode()

Returns

  • text
    String or nil. Decoded text if the image contains a QR code; otherwise nil

Description

Decode an image that contains a QR code. It may still work even if there is background clutter

Examples

-- Decode a local QR image file
local img = image.load_file("/var/mobile/qr.png")
if img then
local str = img:qr_decode()
img:destroy()
if str then
sys.alert("Success\n"..str)
else
sys.alert("Failed")
end
else
sys.alert("Load failed: file may not exist")
end
-- Decode QR code shown on current screen
local str = screen.image():qr_decode()
if str then
sys.alert("Success\n"..str)
else
sys.alert("Failed")
end

Note: Uses function outside this chapter sys.alert