voidCaptureScreenTest::onCaptured(Ref*)
{
Director::getInstance()->getTextureCache()->removeTextureForKey(_filename);
removeChildByTag(childTag);
_filename="CaptureScreenTest.png";
utils::captureScreen(CC_CALLBACK_2(CaptureScreenTest::afterCaptured,this),_filename);
}
voidCaptureScreenTest::afterCaptured(boolsucceed,conststd::string& outputFile)
{
if(succeed)
{
autosp =Sprite::create(outputFile);
addChild(sp,0,childTag);
Sizes =Director::getInstance()->getWinSize();
sp->setPosition(s.width/2, s.height/2);
sp->setScale(0.25);
_filename= outputFile;
}
else
{
log("Capture screen failed.");
}
}
上面是Cocos引擎中C++的截屏實(shí)現(xiàn)方法
在display.lua 源文件中有這個(gè)接口 ?直接調(diào)用就可以實(shí)現(xiàn)截屏了
--------------------------------
-- 截屏并保存為一個(gè)文件
-- @function [parent=#display] captureScreen
-- @param function callback 截屏的回調(diào)函數(shù)
-- @param string fileName 保存的文件, 絕對路徑就直接保存, 只有文件名會保存在writePath下
截屏:
display.captureScreen(
function (bSuc, filePath)
--bSuc 截屏是否成功
--filePath 文件保存所在的絕對路徑
end, "screen.png")