I've used this code for auto-generation of screenshots needed for submitting apps to Apple App Store.
It will generate the 3.5, 4.0, 4.7, 5.5 inch and iPad JPG's.
Screenshots are created in multi-threaded mode on secondary threads so you can keep running the game, and correct aspect ratio is calculated.
Code:
/******************************************************************************/
const Str ScreenShotPath="d:/Screens/";
/******************************************************************************/
class ScreenCapture
{
Image src;
VecI2 res;
Str name;
ScreenCapture& create(C Image &src, C VecI2 &res, C Str &name)
{
src.copy(T.src, -1, -1, -1, -1, IMAGE_SOFT, 1);
T.res=res;
T.name=name;
return T;
}
void process()
{
src.copy(src, res.x, res.y, -1, -1, -1, -1, FILTER_BEST);
src.Export(name, 0.95); src.del(); name.del();
}
static void Process(ScreenCapture &sc, ptr user, int thread_index) {sc.process();}
}
/******************************************************************************/
Memx<ScreenCapture> ScreenCaptures;
bool TakingScreenShot, SkipGUI;
Threads ScreenShotThreads;
/******************************************************************************/
void ScreenShot()
{
if(!TakingScreenShot)
{
TakingScreenShot=true;
SkipGUI=Kb.ctrl();
if(!ScreenShotThreads.threads())ScreenShotThreads.create(true, Cpu.threads()-1);
flt aspect=D.aspectRatio();
void (*draw)()=StateActive.draw;
Str path=FFirst(ScreenShotPath); FCreateDirs(path); path.tailSlash(true);
Image capture;
D.aspectRatio(1920./1080);
draw();
Renderer.capture(capture, -1, -1, IMAGE_R8G8B8, IMAGE_SOFT);
ScreenShotThreads.queue(ScreenCaptures.New().create(capture, VecI2(2208, 1242), path+"5.5.jpg"), ScreenCapture.Process);
ScreenShotThreads.queue(ScreenCaptures.New().create(capture, VecI2(1334, 750), path+"4.7.jpg"), ScreenCapture.Process);
ScreenShotThreads.queue(ScreenCaptures.New().create(capture, VecI2(1136, 640), path+"4.0.jpg"), ScreenCapture.Process);
D.aspectRatio(960./640);
draw();
Renderer.capture(capture, -1, -1, IMAGE_R8G8B8, IMAGE_SOFT);
ScreenShotThreads.queue(ScreenCaptures.New().create(capture, VecI2(960, 640), path+"3.5.jpg"), ScreenCapture.Process);
D.aspectRatio(2048./1536);
draw();
Renderer.capture(capture, -1, -1, IMAGE_R8G8B8, IMAGE_SOFT);
ScreenShotThreads.queue(ScreenCaptures.New().create(capture, VecI2(2048, 1536), path+"iPad.jpg"), ScreenCapture.Process);
D.aspectRatio(aspect);
draw();
TakingScreenShot=false;
SkipGUI=false;
}
}
void ScreenShotFinish()
{
ScreenShotThreads.wait().del();
}
/******************************************************************************/