Android开发中实现整个屏幕截图,首先通过activity对象的getwindow()方法获得整个屏幕的window对象,再通过整个屏幕的window对象的getDecorView()方法获得整个屏幕的view,最后截图的实现,也就是将view转换成bitmap,然后,将bitmap保存为图片文件。
Java代码
    - public static Bitmap takeScreenShot(Activity act) {    
-     if (act == null || act.isFinishing()) {    
-         Log.d(TAG, "act参数为空.");    
-         return null;    
-     }    
-    
-       
-     View scrView = act.getWindow().getDecorView();    
-     scrView.setDrawingCacheEnabled(true);    
-     scrView.buildDrawingCache(true);    
-    
-       
-     Rect statuBarRect = new Rect();    
-     scrView.getWindowVisibleDisplayFrame(statuBarRect);    
-     int statusBarHeight = statuBarRect.top;    
-     int width = act.getWindowManager().getDefaultDisplay().getWidth();    
-     int height = act.getWindowManager().getDefaultDisplay().getHeight();    
-    
-     Bitmap scrBmp = null;    
-     try {    
-           
-         scrBmp = Bitmap.createBitmap( scrView.getDrawingCache(), 0, statusBarHeight,    
-                 width, height - statusBarHeight);    
-     } catch (IllegalArgumentException e) {    
-         Log.d("", "#### 旋转屏幕导致去掉状态栏失败");    
-     }    
-     scrView.setDrawingCacheEnabled(false);    
-     scrView.destroyDrawingCache();    
-     return scrBmp;    
- }