0

I am using this code for saving a screenshot

 Size size = Director::getInstance()->getWinSize();
    auto renderTexture = RenderTexture::create((size.width/5)*3.98, (size.height/5)*3.45, Texture2D::PixelFormat::RGBA8888);
    renderTexture->beginWithClear(0.0f, 0.0f, 0.0f, 0.0f);
    Director::getInstance()->getRunningScene()->visit();
    renderTexture->end();
    renderTexture->saveToFile("screenshot.png" , kCCImageFormatPNG);

How can I save the image file using current system time as the filename like " screenshot" + current time +".png"?

Dwood
  • 31
  • 7

1 Answers1

0

To get system time you can simply use the time() function : docs

As for glueing it into a string together you can use std::stringstream for example.

#include <sstream>
#include <time.h>

//--- in your save method ---
std::stringstream filename;
filename << "screenshot_" << time(NULL) << ".png";

renderTexture->saveToFile(filename.str(), kCCImageFormatPNG);
Losiowaty
  • 7,911
  • 2
  • 32
  • 47
  • It is C++ (`std::` and `stringstream` should clearly indicate that). `time.h` does exits in `C` standard also, but it is perfectly fine to use it in `C++`. AFAIK, pure `C++` time functions were introduced in `C++11`, you can read more about them here : http://en.cppreference.com/w/cpp/chrono – Losiowaty Jul 08 '14 at 07:54