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

Author Topic: Get screenshot  (Read 2055 times)

0 Members and 1 Guest are viewing this topic.

paupav

  • Full Member
  • ***
  • Posts: 156
    • View Profile
    • Email
Get screenshot
« on: August 20, 2014, 08:58:52 pm »
So, is there any way I can save current drawn screen to .png or any other picture format?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: Get screenshot
« Reply #1 on: August 20, 2014, 09:05:41 pm »
You should consider searching before asking...
sf::RenderWindow::capture
sf::Image::saveToFile

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
Re: Get screenshot
« Reply #2 on: August 20, 2014, 09:07:32 pm »

MW2TopTenWORLD

  • Newbie
  • *
  • Posts: 23
    • View Profile
    • Email
Re: Get screenshot
« Reply #3 on: August 20, 2014, 09:11:11 pm »
Hey this is how I do it ( I Put it into the events code block)

case sf::Keyboard::F12:
                                        {
                                                sf::Image screen = window.capture();
                                                srand(time(0));
                                                long double randomNum = 0;
                                                for(int i = 0; i < 5; i++)
                                                {
                                                        randomNum = rand() % 125000000 + 1;
                                                }
                                                string fileName = "Screenshots\\" + std::to_string(randomNum) + ".png";
                                                screen.saveToFile(fileName);
                                                break;
                                        }

I am using a randum num generator for the names of the screens... you dont need to do that

Jesper Juhl

  • Hero Member
  • *****
  • Posts: 1405
    • View Profile
    • Email
« Last Edit: August 20, 2014, 09:41:16 pm by Jesper Juhl »

paupav

  • Full Member
  • ***
  • Posts: 156
    • View Profile
    • Email
Re: Get screenshot
« Reply #5 on: August 20, 2014, 10:10:45 pm »
Hey this is how I do it ( I Put it into the events code block)

case sf::Keyboard::F12:
                                        {
                                                sf::Image screen = window.capture();
                                                srand(time(0));
                                                long double randomNum = 0;
                                                for(int i = 0; i < 5; i++)
                                                {
                                                        randomNum = rand() % 125000000 + 1;
                                                }
                                                string fileName = "Screenshots\\" + std::to_string(randomNum) + ".png";
                                                screen.saveToFile(fileName);
                                                break;
                                        }

I am using a randum num generator for the names of the screens... you dont need to do that

Ty, I've used that!