我使用此代码保存屏幕截图
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);
如何使用当前系统时间将图像文件保存为文件名,如“screenshot”+当前时间+“。png”?
答案 0 :(得分:0)
要获得系统时间,您只需使用time()
功能:docs
至于将它粘合到一个字符串中,您可以使用std::stringstream
。
#include <sstream>
#include <time.h>
//--- in your save method ---
std::stringstream filename;
filename << "screenshot_" << time(NULL) << ".png";
renderTexture->saveToFile(filename.str(), kCCImageFormatPNG);