I created a screenshot extension a while back but never got it working on iOS (captured images were completely black). I took another look at the code today, did some searches on Stack Overflow, added one line of code and lo and behold, the darn thing is working on iOS! I thought I had tried this solution already, but apparently not
Anyway, if you want to capture screenshots then this extension is for you! You can capture the entire screen or a region and you can get the screenshot as a png, buffer or as raw pixels:
-- Take screenshot and encode to a PNG
-- Write it to foo.png
local png, w, h = screenshot.png()
local f = io.open("screenshot1.png", "wb")
f:write(png)
f:flush()
f:close()
-- Take screenshot and return it as a Defold buffer
-- Set buffer as texture on a model
local buffer, w, h = screenshot.buffer()
local url = go.get("cube#model", "texture0")
resource.set_texture(url, { type = resource.TEXTURE_TYPE_2D, width = w, height = h, format = resource.TEXTURE_FORMAT_RGBA }, buffer)
-- Take screenshot and return pixels as a Lua string
local pixels, w, h = screenshot.pixels()
-- Capture screenshots of a portion of the screen
screenshot.png(x, y, w, h)
screenshot.buffer(x, y, w, h)
screenshot.pixels(x, y, w, h)