0

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

这是我的结果:
在此处输入图像描述

// 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");
      }
4

2 回答 2

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;
}
于 2013-04-23T12:51:08.387 回答
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();  
    }
于 2013-04-23T12:54:56.610 回答