如何以编程方式在Android中截取整个屏幕截图?

时间:2013-10-03 07:31:03

标签: android screenshot

我需要在Android中截取整个屏幕的截图,我已经搜索了很多但他们都谈到了截取指定视图的截图,我该如何截取整个屏幕的截图?

我的意思是,按程序。(不是DDMS)

5 个答案:

答案 0 :(得分:1)

有一个库可用于通过设备拍摄快照,名为 ASL(Android屏幕截图库)

查看完整源代码的here

答案 1 :(得分:0)

在eclipse中转到DDMS透视图并选择您的设备。然后单击屏幕截图(相机图片)按钮。

仔细阅读link这对您有所帮助......

答案 2 :(得分:0)

您需要root设备,否则无法使用。此外,你必须让你的应用程序获得超级用户访问权限。只需实现此代码,您就可以了:

public void screenShot() throws InterruptedException
{
    Process sh;
    try
    {
        sh = Runtime.getRuntime().exec("su", null, null);
        OutputStream os = sh.getOutputStream();
        os.write(("/system/bin/screencap -p " + "/sdcard/Image.png").getBytes("ASCII"));
        os.flush();
        os.close();
        sh.waitFor();
    }
    catch (IOException e)
    {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

答案 3 :(得分:-1)

尝试以下代码:

// image naming and path  to include sd card  appending name you choose for file
String mPath = Environment.getExternalStorageDirectory().toString() + "/" + ACCUWX.IMAGE_APPEND;   

// create bitmap screen capture
Bitmap bitmap;
View v1 = mCurrentUrlMask.getRootView();
v1.setDrawingCacheEnabled(true);
bitmap = Bitmap.createBitmap(v1.getDrawingCache());
v1.setDrawingCacheEnabled(false);

OutputStream fout = null;
imageFile = new File(mPath);

try {
fout = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
fout.flush();
fout.close();

} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

请参阅此answer

答案 4 :(得分:-4)

在Eclipse中转到Window - >显示视图 - >其他 - >设备

选择您的设备,然后只需点击“相机图片”:

enter image description here