Reputation: 13
I have to take screenshot of desired screen group but it is not working and totally black image is saved in documents directory . How can I save the screenshot ?
local function takeSnapshot(event)
timer.performWithDelay( 100, captureWithDelay )
end
function captureWithDelay()
local baseDir = system.DocumentsDirectory
display.save( stageGroup, "entireGroup.jpg", baseDir )
end
Upvotes: 0
Views: 892
Reputation: 267
I think you using lower version of graphics drive.Try it in Mac latest.
Upvotes: 1
Reputation: 7390
For saving a display group, you have to:
display group
.add
the screen objects to that group.Return
the display groupdisplay.save
to save the entire group displayed.I am giving a sample here:
-- creating the display group --
local stageGroup = display.newGroup()
-- creating display objects and adding it to the group --
local bg = display.newRect(0,0,_w,_h)
bg.x = 160
bg.y = 240
bg:setFillColor(150)
localGroup:insert(bg)
local rect = display.newRect(0,0,50,50)
rect.x = 30+math.random(260)
rect.y = 30+math.random(420)
localGroup:insert(rect)
-- Then do as follows --
local function takePhoto()
-- take screen shot to baseDirectory --
local baseDir = system.DocumentsDirectory
display.save( stageGroup, "myScreenshot.jpg", baseDir )
end
rect:addEventListener("tap",takePhoto)
Note: Make sure that you have added the objects to be appear on the screenshot to the stageGroup.
Keep Coding............. :)
Upvotes: 1