Posted: 19th May 2022 19:10
Here is an updated version of the Screenshot() function found here:
https://forum.thegamecreators.com/thread/225040#msg2648153
I'm creating this new post because that thread does not contain the word "screenshot" in the title, making it difficult to search for.


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.

Update 2022-06-04:
It appears GetImage( 0, 0, GetWindowWidth(), GetWindowHeight() ) gets confused in fullscreen and gives odd sized images.
This appears to create correctly sized images: GetImage( GetScreenBoundsLeft(), GetScreenBoundsTop(), GetScreenBoundsRight(), GetScreenBoundsBottom() )

New Version:
+ Code Snippet
FUNCTION ScreenShot()
    TheScreenshot AS INTEGER : TheScreenshot = GetImage( GetScreenBoundsLeft(), GetScreenBoundsTop(), GetScreenBoundsRight(), GetScreenBoundsBottom() ) // 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
Posted: 26th Jul 2022 10:22
Hello @Nieb

I tested your screenshot code but it failed to work for me. It only captures the Print statements for me, I simply created a red box, pointed the camera at the box, but the screenshot only shows the FPS meter, this is my code:
+ Code Snippet
// Project: TestScreenshot 
// Created: 2022-07-26

// show all errors
SetErrorMode(2)

// set window properties
SetWindowTitle( "TestScreenshot" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window

// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts

CreateObjectBox(1, 1, 1, 1)
SetObjectColor(1, 255, 0, 0, 0)
SetCameraPosition(1, 0, 2, 0)
SetCameraLookAt(1, 0, 0, 0, 0)
 
// How to use ( must be placed after Render() and before Swap() ):
DO
    // ** Game Code Here **
	Print(ScreenFPS())
    Render()
    IF GetRawKeyPressed(123) THEN ScreenShot()
    Swap()
LOOP


FUNCTION ScreenShot()
    TheScreenshot AS INTEGER : TheScreenshot = GetImage( GetScreenBoundsLeft(), GetScreenBoundsTop(), GetScreenBoundsRight(), GetScreenBoundsBottom() ) // 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


Can you confirm the same problem?

Thank you
Posted: 3rd Aug 2022 1:13
The object is transparent:
SetObjectColor(1, 255, 0, 0, 0) ---> SetObjectColor(1, 255, 0, 0, 255)

[s]Now, the question is, why are we able to see it in the window?[/s] It will only go transparent, partially or fully, if SetObjectTransparency() is enabled.

[s]Now, why/how is the transparency working with GetImage()?[/s]
Upon pondering this, I'm pretty sure the front buffer doesn't do anything with alpha, it's just RGB values for the video-out. So, all those pixels were rendered with zero alpha, but the color channels were still written as well. And that color is revealed when the buffer swap occurs.