Google Map V1的屏幕截图

时间:2013-04-23 12:20:08

标签: android screenshot

当我屏幕截图时。我无法成功拍摄全屏幕。只显示路径。 我想知道我的代码问题是什么。我希望有一个人可以帮助我。谢谢

这是我的结果:
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");
      }

2 个答案:

答案 0 :(得分:0)

尝试此代码,并在此

中传递mapView
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;
}

答案 1 :(得分: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();  
    }