java-有没有办法用codenameone截屏(特别是对于Android)?

我试图每秒拍摄一次屏幕快照,以找出用户是否在另一个应用程序的菜单中.我在Display中找到了一个名为capturePhoto(…)的函数,但这是一个无效函数.我也用Robot尝试过,但不支持.

我用谷歌搜索,但只发现文本未使用代码.

我发现的功能:Display.getInstance().capturePhoto(null);

我不知道那里是什么,而不是null

最佳答案

要使用Codename One截屏,可以使用以下静态方法:

    /**
     * Returns a screenshot of the currently displayed Form, or null if no form
     * is shown
     *
     * @return
     */
    public static Image getScreenshot() {
        Form form = Display.getInstance().getCurrent();
        if (form != null) {
            Image screenshot = Image.createImage(form.getWidth(), form.getHeight());
            form.paintComponent(screenshot.getGraphics(), true);
            return screenshot;
        } else {
            return null;
        }
    }

它可以在Codename One支持的所有平台上运行,不仅适用于Android.

发布了540 篇原创文章 · 获赞 0 · 访问量 1959

猜你喜欢

转载自blog.csdn.net/weixin_44109689/article/details/103934374