SFML community forums

Help => Graphics => Topic started by: KapSKY on April 12, 2020, 02:05:08 pm

Title: Screen capture in C++
Post by: KapSKY on April 12, 2020, 02:05:08 pm
Welcome,

I want write program to screen capture. Im was trying to this:
    sf::Image oknoAplikacji;    sf::Image zrzutEkranu = oknoAplikacji.Capture();
    zrzutEkranu.SaveToFile( "zrzut-ekranu.png" );

But there's no .capture method.
I tryied to use SFML 2.5.1 and SFML 1.6
Title: Re: Screen capture in C++
Post by: Laurent on April 12, 2020, 06:48:56 pm
You want to capture the contents of you sf::RenderWindow. So search there for a capture() function, not in sf::Image.

https://www.sfml-dev.org/documentation/2.5.1/classsf_1_1RenderWindow.php#a5a784b8a09bf4a8bc97ef9e0a8957c35

(note the deprecation warning, that mentions the best method to use)
Title: Re: Screen capture in C++
Post by: KapSKY on April 13, 2020, 12:59:26 pm
I did it but
there is an error: Failed to create texture, invalid size (0x0) and Failed to save image "screen.png"

    sf::RenderWindow window;
    sf::Image image;
    image = window.capture();
    image.saveToFile( "screen.png" );
Title: Re: Screen capture in C++
Post by: Laurent on April 13, 2020, 02:41:07 pm
Your window must obviously be initialized properly, and show some stuff. You can't capture a default-constructed window ;)
Title: Re: Screen capture in C++
Post by: eXpl0it3r on April 13, 2020, 11:25:07 pm
And if your intention was to capture the whole screen and not the SFML window, then that's not something you can do with SFML. Instead, I highly recommend using OBS for screen and even game capturing.