2014-03-25 202 views
0

我如何從手機屏幕截取手機屏幕的截圖,而不是通過任何程序,而是通過代碼。如何在Android中以編程方式拍攝屏幕截圖?

+0

檢查此鏈接:http://stackoverflow.com/questions/2661536/how-to-programatically-take-a -screenshot-on-android – Kanika

+0

和普通截圖一樣,但刪除用戶輸入和「只是做」。 – Parrotmaster

+0

http://stackoverflow.com/questions/6056000/android-screenshot-from-code-got-it-but-not-perfect 你的答案在上面的頁面上。 – TheDerpDeveloper

回答

0

請參閱this鏈接。在發佈問題之前,請先搜索類似的問題。

+0

感謝您的建議。我搜索了很多,但找不到解決方案 –

+0

您是否嘗試過以上鍊接? – prabhu

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

然後,當你需要訪問使用這樣的事情:

Uri uri = Uri.fromFile(new File(mPath)); 
相關問題