cocos2d-x如何截屏并保存图片

static void ScreenShoot()
{
    CCSize size = CCDirector::sharedDirector()->getWinSize();  
    //定义一个屏幕大小的渲染纹理  
    CCRenderTexture* pScreen = CCRenderTexture::create(size.width,size.height, kCCTexture2DPixelFormat_RGBA8888);  
    //获得当前的场景指针  
    CCScene* pCurScene = CCDirector::sharedDirector()->getRunningScene();  
    //渲染纹理开始捕捉  
    pScreen->begin();  
    //当前场景参与绘制  
    pCurScene->visit();  
    //结束捕捉  
    pScreen->end();  
    //保存为png
    pScreen->saveToFile("XXXXXX.png", kCCImageFormatPNG);  
    //保存为jpg
    pScreen->saveToFile("XXXXXX.jpg", kCCImageFormatJPEG);  
     CC_SAFE_DELETE(pScreen); 
}

你可能感兴趣的:(cocos2d-x)