2013-10-03 124 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(); 
    } 

} 
相關問題