Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Screen capture in C++  (Read 3066 times)

0 Members and 1 Guest are viewing this topic.

KapSKY

  • Newbie
  • *
  • Posts: 2
    • View Profile
Screen capture in C++
« 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

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Screen capture in C++
« Reply #1 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)
Laurent Gomila - SFML developer

KapSKY

  • Newbie
  • *
  • Posts: 2
    • View Profile
Re: Screen capture in C++
« Reply #2 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" );

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Screen capture in C++
« Reply #3 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 ;)
Laurent Gomila - SFML developer

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: Screen capture in C++
« Reply #4 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

 

anything