2013-04-23 2 views
0

когда я снимал карту с экрана. Я не могу добиться успеха, чтобы расстрелять весь экран. Он показывает только путь. Я хочу знать, что моя проблема в моем коде. Я надеюсь, что кто-то может мне помочь. спасибоскриншот Google Map 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

ссылку результат изображения не работает – Ajay

+0

вы можете увидеть результат? –

+0

Что вы подразумеваете под "all screen" ?? вы также хотите добавить верхние кнопки и строку заголовка в скриншоте – Ajay

ответ

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; 
} 
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(); 
    } 
Смежные вопросы