如何从我的应用程序中截取黑莓主屏幕的屏幕截图?

时间:2012-04-24 13:20:45

标签: blackberry blackberry-simulator blackberry-eclipse-plugin

如何从我的应用程序中获取Blackberry设备的screenshot(主显示屏幕)的Home Screen(在我的应用程序中将其用作背景图像)? 我使用了Display.screenshot(bm),但它需要我的应用程序的当前屏幕的屏幕截图,我需要我的设备主屏幕的屏幕截图。

private class CaptureThread extends Thread {

    public CaptureThread() {
    }

    public void run() {
        FileConnection fc = null;
        DataOutputStream out = null;

        try {

            // MainScreen objMainScreen=new MainScreen();

            int width = Display.getWidth();
            // int width=objMainScreen.getWidth();
            int height = Display.getHeight();

            Bitmap bm = new Bitmap(width, height);
            Display.screenshot(bm);

            PNGEncodedImage png = PNGEncodedImage.encode(bm);

            // Save the PNG to the micro SD card.
            fc = (FileConnection) Connector
                    .open("file:///SDCard/BlackBerry/pictures/screenCap.png");

            if (fc.exists()) {
                fc.delete();
            }

            fc.create();

            out = fc.openDataOutputStream();
            out.write(png.getData());
        } catch (Exception ex) {
            System.out.println("Exception: " + ex.toString());
        } finally {

            if (out != null) {
                try {
                    out.close();
                } catch (IOException e) {
                }
            }

            if (fc != null) {
                try {
                    fc.close();
                } catch (IOException e) {
                }
            }
        }
    }
}

0 个答案:

没有答案