Snapshot from the map in android

2020-08-02 07:07发布

问题:

I want to make a snapshot of a particular location from the map by calling intent or from a mapview.Can anyone help me.I am not getting the snapshot.

回答1:

Try this post, I believe this should help. It involves enabling the drawing cache and forcing it use that cache. Usually works on all views. Should work on MapView aswell

Code from the link

 private Bitmap getMapImage() {  
        /* Position map for output */  
        MapController mc = mapView.getController();  
        mc.setCenter(SOME_POINT);  
        mc.setZoom(16);  

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

        return bmp;  
    }  

    private void saveMapImage() {  
        String filename = "foo.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();  
    }