2013-10-03 125 views
2

我需要在Android中截取整个屏幕截图,我搜索了很多,但他们都谈到了指定视图的截图,我怎么能截屏整个屏幕?如何在Android中以编程方式截屏整个屏幕?

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

+2

这取决于你使用哪个手机。在少数手机中,您可以将音量调低按钮和电源按钮放在一起,将屏幕截图存储在手机屏幕截图文件夹中。我宁愿建议通过USB将您的设备连接到系统。并通过Eclipse - > DDMS,您可以在手机上截取当前屏幕。 – khubaib

+0

我已编辑我的答案,并看到编程方式在Android上截图的链接 – Vamshi

回答

1

没有可用于拍摄快照,通过设备将其称为ASL(安卓截图库)库。

看一看here完整的源代码

0

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

通过这个link它可能对你有所帮助......

-3

在Eclipse中去窗口 - >显示视图 - >其他 - >设备

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

enter image description here

+1

阅读提问的问题.. !! – Noman

-1

您也可以使用adb命令(采取截图 - >复制文件在桌面上 - >打开文件 - >从设备上删除截图):

adb shell /system/bin/screencap -p /sdcard/screenshot.png 
adb pull /sdcard/screenshot.png screenshot.png 
adb pull /sdcard/screenshot.png c:\Users\username\Desktop\screenshot.png 
c:\Users\username\Desktop\screenshot.png 
adb shell rm /sdcard/screenshot.png 
-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

+1

试着解释为什么答案是赞成票,谢谢! – 2013-10-03 12:49:38

+0

@ Matt_9.0 ..什么是mCurrentUrlMask? – Noman

+0

@Noman我发布了[链接](http://stackoverflow.com/a/5651242/2003486)从我实际提到的答案。有关于相同和最后的评论有一个讨论..'Insted of View v1 = mCurrentUrlMask.getRootView();我已经使用View v1 = getWindow()。getDecorView()。getRootView();它适用于我。“是其中一位用户的评论。所以我认为这可能会奏效。 – 2014-03-18 04:15:26

0

你需要为你的设备创建根目录,否则它将无法工作。另外你必须让你的应用程序获得超级用户访问权限。只是实现这个代码,你会很好去:

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(); 
    } 

} 
相关问题