2013-04-23 60 views
0

當我屏幕截圖的時候。我無法成功地拍攝所有屏幕,只顯示路徑。 我想知道我的代碼有什麼問題。我希望有一個人可以幫助我。謝謝谷歌地圖V1的截圖

這是我的結果:
enter image description here

// Screen shot 
     private static Bitmap takeScreenShot(Activity activity) { 
     // View to shot View 
     View view = activity.getWindow().getDecorView(); 
     //View view = getPopupViews(getDecorViews())[0]; 
     Log.i("ABC", view.getClass().getName()); 
     view.setDrawingCacheEnabled(true); 
     view.buildDrawingCache(); 
     Bitmap b1 = view.getDrawingCache(); 

     // the height 

     Rect frame = new Rect(); 

     view.getWindowVisibleDisplayFrame(frame); 

     int statusBarHeight = frame.top; 

     System.out.println(statusBarHeight); 

     // width and height 

     int width = activity.getWindowManager().getDefaultDisplay().getWidth(); 

     int height = activity.getWindowManager().getDefaultDisplay().getHeight(); 

     // del the state bar 

     // Bitmap b = Bitmap.createBitmap(b1, 0, 25, 320, 455); 

     Bitmap b = Bitmap.createBitmap(b1, 0, statusBarHeight, width, height - statusBarHeight); 

     view.destroyDrawingCache(); 

     return b; 

} 

// save image to sdcard 

private static void savePic(Bitmap b, String strFileName) { 
     FileOutputStream fos = null; 
     try { 
       fos = new FileOutputStream(strFileName); 
       if (null != fos) { 
         b.compress(Bitmap.CompressFormat.JPEG, 90, fos); 
         fos.flush(); 
         fos.close(); 
       } 

     } catch (FileNotFoundException e) { 

       e.printStackTrace(); 

     } catch (IOException e) { 

       e.printStackTrace(); 

     } 
     } 

    private void shoot() { 
    shoot(this); 

     } 

    // call function 
    public static void shoot(Activity a) { 
      savePic(takeScreenShot(a), "data/data/com.example.map/"+number+".png"); 
     } 
+0

結果圖像鏈接嘗試這個代碼,並通過MapView的不工作 – Ajay 2013-04-23 12:22:26

+0

可以看到現在結果? – 2013-04-23 12:28:25

+0

「全屏」是什麼意思?你還想在屏幕截圖中添加上方按鈕和標題欄 – Ajay 2013-04-23 12:36:58

回答

0

在此

public final static Bitmap takeScreenShot(View view) { 
    Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Config.ARGB_8888); 
    Canvas canvas = new Canvas(bitmap); 
    view.draw(canvas); 
    return bitmap; 
} 
0
private Bitmap getMapImage() { 

     MapController mc = mapView.getController(); 
     mc.setCenter(GEO_POINT); 
     mc.setZoom(ZOOM_LEVEL); 

     /* Capture drawing cache as bitmap */ 
     mapView.setDrawingCacheEnabled(true); 
     Bitmap bmp = Bitmap.createBitmap(mapView.getDrawingCache()); 
     mapView.setDrawingCacheEnabled(false); 

     return bmp; 
    } 

    private void saveMapImage() { 
     String filename = "SCREEN_SHOT.png"; 
     File f = new File(getExternalFilesDir(null), filename); 
     FileOutputStream out = new FileOutputStream(f); 

     Bitmap bmp = getMapImage(); 

     bmp.compress(Bitmap.CompressFormat.PNG, 100, out); 

     out.close(); 
    }