【问题标题】:the screenshot of Google Map V1谷歌地图V1截图
【发布时间】:2013-04-23 20:54:56
【问题描述】:

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

这是我的结果:

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

【问题讨论】:

  • 结果图片链接失效
  • 现在可以看到结果了吗?
  • “全屏”是什么意思??你是否也想在屏幕截图中添加上部按钮和标题栏
  • 我想显示地图背景。现在,它只显示路径
  • 这个问题是由于map api key,请更新你的map api key。

标签: android screenshot


【解决方案1】:

试试这段代码,并在其中传递 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;
}

【讨论】:

    【解决方案2】:
     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();  
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多