2013-02-27 222 views
1

我想以編程方式截取Android設備的屏幕截圖。以屏幕截圖(以編程方式)

我知道這個問題已被問了很多次。我知道有兩種方法可以做到這一點。

  1. 使用截圖庫(但我越來越黑屏)。
  2. 從幀緩衝區獲取數據從\dev\graphics\fb0生根(但它總是0字節,我不知道設備的當前屏幕截圖存儲的確切位置)。我首選的要求也越來越好框架rate.My代碼

    public void onCreate(Bundle savedInstanceState) 
    { 
        super.onCreate(savedInstanceState); 
        setContentView(R.layout.main); 
    
        Intent intent = new Intent(); 
        intent.setClass(this, ScreenshotService.class); 
        bindService (intent, new ServiceConnection() { 
    
        @Override 
        public void onServiceDisconnected(ComponentName name) 
        { 
    
        } 
        @Override 
        public void onServiceConnected(ComponentName name, IBinder service) { 
         try { 
          asl = IScreenshotProvider.Stub.asInterface(service); 
         } catch (Exception ex) { 
          Log.e("errrorrrrrrrrrrrrr","errrorrrrrrrrrrr", ex); 
         } 
        } 
    }, Context.BIND_AUTO_CREATE); 
    Button b1=(Button) this.findViewById(R.id.widget33); 
    b1.setOnClickListener(new OnClickListener() { 
    
        public void onClick(View view) 
        { 
         try { 
          asl.takeScreenshot(); 
         } catch (RemoteException ex) { 
          Log.e("nnnnerrrrrrrrrrrrrr","errrrrrrrrrrrrr",ex); 
         } 
        } 
    }); 
    }' 
    
+0

Android沒有內置的截圖庫。你在說什麼圖書館? – 2013-02-27 16:58:21

+0

Linux上的路徑分隔符是'/'not \。 – m0skit0 2013-02-27 16:59:19

+0

你是在談論以編程方式獲取屏幕截圖,還是僅僅使用其他應用程序,或者從Eclipse或...? – Phil 2013-02-27 17:02:14

回答

0

不要發佈超過一次一個問題更多。

您可以用下面的代碼獲取您的視圖的繪製緩存:

view.setDrawingCacheEnabled(true); 
view.buildDrawingCache(); 
Bitmap b1 = view.getDrawingCache(); 
+0

我不想只截取我的應用程序的截圖但是設備屏幕上顯示的任何內容 – WSS 2013-02-28 02:50:11

0

通常,當您使用的截圖,我們得到的屏幕圖像。你說的是運行它,這也可能是一個設備的東西,所以我建議你嘗試在其他設備上使用它。

還有一段時間問題可能會在將文件寫回到sd時發生。所以請提供您嘗試的完整代碼。

相關問題