2013-07-18 39 views
4

根植設備上的屏幕截圖 我想要捕獲使用APK生根的Android設備的屏幕。 我試過根植設備上的Android屏幕截圖

process = Runtime.getRuntime().exec("/system/bin/screencap -p " + path + 」/file.png 」); 

該命令工作正常,但速度太慢。 然後我嘗試使用第二個選項

View content = findViewById(android.R.id.content).getRootView(); 
content.setDrawingCacheEnabled(true); 
Bitmap bitmap = Bitmap.createBitmap(content.getDrawingCache()); 
OutputStream fout = null; 
File imageFile = new File(_path,"ScreenImage.png"); 
try { 
    fout = new FileOutputStream(imageFile); 
    bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout); 
    fout.flush(); 
    fout.close(); 
} catch (FileNotFoundException e) { 
    e.printStackTrace(); 
} catch (IOException e) { 
    e.printStackTrace(); 
} 

但在這我得到我的觀點不應用當前屏幕。 我是捕捉屏幕截圖的製作視頻了出來,我使用FB0進行視頻,但要問題是每秒

請建議的解決方案8幀的速度拍攝畫面加快這一進程。分辨率不是問題,它可能是質量差。

+0

這是活動或服務內的代碼? –

+0

http://stackoverflow.com/questions/14242131/device-specific-screen-capturing-on-android –

回答

1

由於您的設備是植根,看看框架隱藏API SurfaceControl的截圖方法。沒有測試它是否足夠快。

public static Bitmap screenshot(int width, int height) { 
    // TODO: should take the display as a parameter 
    IBinder displayToken = SurfaceControl.getBuiltInDisplay(
      SurfaceControl.BUILT_IN_DISPLAY_ID_MAIN); 
    return nativeScreenshot(displayToken, width, height, 0, 0, true); 
} 

正常步驟採取截圖,攔截在PhoneWindowManager截圖組合鍵,然後連接到一個屏幕截圖服務在systemui,這種服務將調用方法SurfaceControl.screenshot採取的屏幕截圖。