I've been using the code below to take screenshots for a windowed screen on Windows PC x64, but on the DirectX11 subsystem the screenshots are corrupted. I ended up having to switch to OpenGL to fix the problem. A dedicated screenshot function might have prevented this issue or made it easier to debug by having a single function with a well defined purpose, rather than messing around with the 2D drawing library.
Code: Select all
DrawPuzzle()
If StartDrawing( ScreenOutput() )
DrawingMode( #PB_2DDrawing_AllChannels ) ; This is required for the DirectX11 and OpenGL subsytems.
screenshot = GrabDrawingImage( #PB_Any, 0, 0, ScreenWidth() - 1, ScreenHeight() - 1 )
StopDrawing()
If screenshot
; Create a unique filename.
increment = 0
Repeat
filepath.s = G_screenshots_folderpath.s + Str( Abs( ElapsedMilliseconds() + increment ) ) + ".jpg"
increment + 1
Until FileSize( filepath.s ) = -1
If SaveImage( screenshot, filepath.s, #PB_ImagePlugin_JPEG, 8 )
Message( "Screenshot was saved to: " + filepath.s )
Else
Error( "Screenshot could not be saved to file. File storage may be full." )
EndIf
FreeImage( screenshot )
Else
Error( "Unable to create screenshot image. Possibly out of memory." )
EndIf
EndIf