自己写的,亲测能用,有问题请指出
function ScreenShot( bFullScreen, screenRect )
--是否截全屏,不是全屏的话需要指定区域
if bFullScreen == nil or screenRect == nil then
bFullScreen = true;
end
local fileName = "screenShot.png";
cc.utils:captureScreen( function ( succeed, outputFile )
if succeed then
print( "succeed "..outputFile );
if bFullScreen == false then
local rt = cc.RenderTexture:create( screenRect.width, screenRect.height );
rt:beginWithClear( 0,0,0,0 );
local sp = cc.Sprite:create( outputFile, screenRect );
--锚点设为(0,0)才行,可以改动看下效果就知道是怎么回事了
sp:setAnchorPoint( 0,0 );
if sp then
sp:visit();
end
rt:endToLua();
--IMAGE_FORMAT_JPEG, IMAGE_FORMAT_PNG
local ret = rt:saveToFile( fileName, cc.IMAGE_FORMAT_PNG, true );
if ret then
print("save ok");
else
print("not ok");
end
cc.Director:getInstance():getTextureCache():removeTextureForKey( fileName );
end
else
print( "failed" );
end
end, fileName );
end