0

I am searching about how to save the image of map from mapview. But still found nothing. I used the below code but I still got the error of "Unable to start Activity... NullPointer Exception".

I am stuck on this query. Has anyone managed to do this?

    mapView.setWillNotCacheDrawing(false);
    mapView.destroyDrawingCache();
    mapView.buildDrawingCache();

    // Copy the drawing cache before the system recycles it
    Bitmap cachedImage = Bitmap.createBitmap(mapView.getDrawingCache());

    Bitmap bmap = Bitmap.createBitmap(mapView.getWidth(), mapView.getHeight(),
                                Bitmap.Config.ARGB_8888);
        Canvas offscreencanvas = new Canvas(bmap);
        offscreencanvas.drawBitmap(cachedImage, 0, 0, null);
anddev
  • 3,144
  • 12
  • 39
  • 70

2 Answers2

1

For getting solution of this problem you should take screen shot of the device when map is running we are able to capture screen shot of the device with out using the camera in android. Here i am giving some use full link related to it read it.

Android take screenshot via code

Take Screenshot of Android screen and save to SD card

I hope it is very useful to you.

Community
  • 1
  • 1
DynamicMind
  • 4,240
  • 1
  • 26
  • 43
0

void snapshot (GoogleMap.SnapshotReadyCallback callback) method was already added to GoogleMap API. You should use it. buildDrawingCache doesn't work for MapView cause map itself is rendering on SurfaceView which doesn't use View's drawing cache.

amukhachov
  • 5,822
  • 1
  • 41
  • 60