Here's a function I've been using. Be sure to place it at the end of your gameloop to make sure everything is up to date & rendered for the screenshot.
*Edit 2022-05-19*
I've just noticed a built-in command called GetImage() for dumping the BackBuffer to an image. Perhaps this is something new?
It's much easier to work with, also it doesn't have issues with Draw() commands being upside-down.
New Version:
FUNCTION ScreenShot()
TheScreenshot AS INTEGER : TheScreenshot = GetImage( 0, 0, GetWindowWidth(), GetWindowHeight() ) // Creates an Image from BackBuffer.
FileName AS STRING
FileName = GetCurrentDate() + "_" + GetCurrentTime() + ".png"
FileName = ReplaceString( FileName , chr(58) , chr(46) , -1 ) // Replace ":" with ".", ":" is not allowed in file names.
SaveImage(TheScreenshot, "screenshot\" + FileName)
DeleteImage(TheScreenshot)
ENDFUNCTION
// How to use ( must be placed after Render() and before Swap() ):
DO
// ** Game Code Here **
Render()
IF GetRawKeyPressed(123) THEN ScreenShot() // [F12]
Swap()
LOOP
Old Version:
IF GetRawKeyPressed(123) THEN ScreenShot() // F12
FUNCTION ScreenShot()
TheScreenshot AS INTEGER : TheScreenshot = CreateRenderImage(GetDeviceWidth(),GetDeviceHeight(),0,0)
SetRenderToImage(TheScreenshot,-1)
ClearScreen() : Render()
SetRenderToScreen()
FileName AS STRING
FileName = GetCurrentDate() + "_" + GetCurrentTime() + ".png"
FileName = ReplaceString( FileName , chr(58) , chr(46) , 1000 )
SaveImage(TheScreenshot,"raw:"+GameDataDir+"screenshot\" + FileName)
DeleteImage(TheScreenshot)
ENDFUNCTION