在Corona sdk上捕获屏幕

我尝试了许多使用 Corona SDK 捕捉屏幕的方法,我阅读了 http://docs.coronalabs.com/api/library/display/captureScreen.htmlCorona:如何在 Corona 中捕捉屏幕?。然而,当我运行程序时,Corona SDK 就会冻结,我不得不关闭它。我正在使用 Corona SDK for Windows,并且有时会遇到“运行时错误 R6025 PURE virtual function call”,我尝试了很多样例代码,这些代码在其他地方都能正常运行。以下是我的代码:

_W = display.viewableContentWidth
_H = display.viewableContentHeight
local background = display.newRect(0, 0, 320, 480);
background:setFillColor(255,255,255);
local foo = display.newImageRect("images/foo.png",100,100);
foo.anchorX=0.5
foo.anchorY=0.5
foo.x = _W * 0.5;
foo.y = _H * 0.5;
local screenShot = display.captureScreen(true);
foo:removeSelf();
background:removeSelf();
screenShot.xScale = 0.5;
screenShot.yScale = 0.5;
screenShot.rotation = 45;

这是我的 build.settings 文件内容:

androidPermissions =
{
    "android.permission.VIBRATE",
    "android.permission.WRITE_EXTERNAL_STORAGE"
},
点赞
用户1078537
用户1078537

你也可以尝试使用 display.save 将屏幕保存到文件中。

查看 Lerg 的代码 以了解如何操作。

这段代码会在按下 “s” 键时在模拟器中保存截图:

if app.isSimulator then
    Runtime:addEventListener('key', function (event)
        if event.keyName == 's' and event.phase == 'down' then
            local scene = storyboard.getScene(storyboard.getCurrentSceneName())
            if scene and scene.view then
                display.save(scene.view, display.pixelWidth .. 'x' .. display.pixelHeight .. '_' .. math.floor(system.getTimer()) .. '.png')
                return true
            end
         end
    end)
end
2014-07-25 22:20:55
用户5401359
用户5401359

你可以使用 display.save() 函数来保存从给定的显示组截图,这个显示组作为函数的第一个参数传递。

2018-09-20 08:48:11