Question

I have an app with a ViewSwitcher which holds a MapView and another View and I want to save the MapView's bitmap as an image. This works well, if the MapView has been visible at least once by doing something like that:

mapView.setDrawingCacheEnabled(true);
Bitmap bm = mapView.getDrawingCache();
/* ... save bitmap ... */

Problem is, if the MapView hasn't been visible, getDrawingCache() returns null for the bitmap. Is there any way how I can resolve that?

Was it helpful?

Solution

I found out how to do it. There are two things to do:

To get the bitmap, create your own one and make the MapView draw into it:

    Bitmap bm = Bitmap.createBitmap(400, 400, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bm);
    mapView.draw(canvas);

If you do so, you'll have all your overlays in the bitmap, but not the map image (the tiles). To achieve that too, you'll have to invoke mapView.preLoad() prior to drawing the map onto your bitmap.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top