We should open a request for this feature!
This has worked for me:
local function screenshot() --I set the filename to be "widthxheight\_time.png" --e.g. "1920x1080\_20140923151732.png" local date = os.date( "\*t" ) local timeStamp = table.concat({date.year .. date.month .. date.day .. date.hour .. date.min .. date.sec}) local fname = display.pixelWidth.."x"..display.pixelHeight.."\_"..timeStamp..".png" --capture screen local capture = display.captureScreen(false) --make sure image is right in the center of the screen capture.x, capture.y = display.contentWidth \* 0.5, display.contentHeight \* 0.5 --save the image and then remove local function save() display.save( capture, { filename=fname, baseDir=system.DocumentsDirectory, isFullResolution=true } ) capture:removeSelf() capture = nil end timer.performWithDelay( 100, save, 1) return true end --works in simulator too local function onKeyEvent(event) if event.phase == "up" then --press s key to take screenshot which matches resolution of the device if event.keyName == "s" then screenshot() end end end Runtime:addEventListener("key", onKeyEvent)
I’ll give it a try, thanks!
Hello,
I have been trying to use this code to take screenshots of my app. I have inserted it into the main.lua file.
The screenshot is taking place, but when I look in my Documents directory, I can’t see the images anywhere.
Are you sure it’s working? No error messages in the console?
No errors show up in the console. I added “print(“Image Saved”)” to the save function, and that pops up in the simulator when I press the S key, but the picture doesn’t seem to save.
Are you looking in the right folder? On Windows, the pictures save to My Pictures\Corona Simulator, not My Documents.
EDIT: This would be for display.captureScreen(), which the thread mentioned, but I’m not sure if you’re using that are the other code that was suggested.
- Andrew
I can’t find the images or a Corona Simulator folder in neither the Documents or Pictures folders.
Does anyone using a mac know where these pictures save to?
Ah I see where the confusion lies. They don’t go into your documents folder on your Mac/PC. Each project in the simulator has it’s own Documents folder.
With the project open in the simulator, go to the menu at the top of the screen:
File/Show Project Sandbox
That will take you to a folder with a name like “YourProjName-B1V23UYGK50978CVQFVC87SFYUHJ43” and in there is the Documents folder for your app.
Hello,
I have been trying to use this code to take screenshots of my app. I have inserted it into the main.lua file.
The screenshot is taking place, but when I look in my Documents directory, I can’t see the images anywhere.
Are you sure it’s working? No error messages in the console?
No errors show up in the console. I added “print(“Image Saved”)” to the save function, and that pops up in the simulator when I press the S key, but the picture doesn’t seem to save.
Are you looking in the right folder? On Windows, the pictures save to My Pictures\Corona Simulator, not My Documents.
EDIT: This would be for display.captureScreen(), which the thread mentioned, but I’m not sure if you’re using that are the other code that was suggested.
- Andrew
I can’t find the images or a Corona Simulator folder in neither the Documents or Pictures folders.
Does anyone using a mac know where these pictures save to?
Ah I see where the confusion lies. They don’t go into your documents folder on your Mac/PC. Each project in the simulator has it’s own Documents folder.
With the project open in the simulator, go to the menu at the top of the screen:
File/Show Project Sandbox
That will take you to a folder with a name like “YourProjName-B1V23UYGK50978CVQFVC87SFYUHJ43” and in there is the Documents folder for your app.
Dear Allan Quiztix,
I try your code but it did not save to the device… I change the false to true value under the captureScreen and it save to the device but the problem is the filename became Picture#.png where # is the number of picture…
I need to capture my screen what ever is there and save in the device with the specific filename I want… I don’t want to capture a specific or group of object… I want to capture what ever in the screen at the time I press the button…
is there somebody can help?
thanks…
Sorry Alan QuizTix,
I followed what you written where andn it’s true you can find it in the documents under sandbox… but my problem where I test it to the device (android phone) I can’t see it… may I know when I can see the saved picture? which folder?
thanks…
In order to make this work for iOS devices in the simulator on Windows, change the event listener to detect an accelerometer shake. iOS on the windows simulator does not support keyboard key events. To simulate a shake, press [CTRL]+I. Hope that helps.
local function onShake (event) if event.isShake then screenshot() end end Runtime:addEventListener("accelerometer", onShake)
Dear Allan Quiztix,
I try your code but it did not save to the device… I change the false to true value under the captureScreen and it save to the device but the problem is the filename became Picture#.png where # is the number of picture…
I need to capture my screen what ever is there and save in the device with the specific filename I want… I don’t want to capture a specific or group of object… I want to capture what ever in the screen at the time I press the button…
is there somebody can help?
thanks…
Sorry Alan QuizTix,
I followed what you written where andn it’s true you can find it in the documents under sandbox… but my problem where I test it to the device (android phone) I can’t see it… may I know when I can see the saved picture? which folder?
thanks…