void A::screenShoot() { //定义一个屏幕大小的渲染纹理 CCRenderTexture* renderTexture = CCRenderTexture::create(m_visibleSize.width * .5, m_visibleSize.height * .5, CCTexture2DPixelFormat::kTexture2DPixelFormat_RGBA8888); CCScene * curScene = CCDirector::sharedDirector()->getRunningScene(); CCPoint ancPos = curScene->getAnchorPoint(); //渲染纹理开始捕捉 renderTexture->begin(); // 缩小屏幕截屏区域 curScene->setScale(.5); curScene->setAnchorPoint(CCPoint(0, 0)); //绘制当前场景 curScene->visit(); //结束 renderTexture->end(); //保存png renderTexture->saveToFile("screenshoot.png", tCCImageFormat::kCCImageFormatPNG); // 恢复屏幕尺寸 curScene->setScale(1); curScene->setAnchorPoint(ancPos); //CC_SAFE_DELETE(curScene); }
转自:http://www.cocos2dev.com/?p=522