I’ve tried both methods to save a MapView as a bitmap which I’ve found here and none seem to work for me. The first option,
Bitmap bitMap = mMapView.getDrawingCache();
mMapView.setDrawingCacheEnabled(true);
bitMap = mMapView.getDrawingCache(true);
and the second,
Canvas offscreencanvas = new Canvas();
Bitmap bmap = Bitmap.createBitmap(mMapView.getWidth(), mMapView.getHeight(),
Bitmap.Config.ARGB_8888);
bmap.copy(Config.ARGB_4444, true);
offscreencanvas.setBitmap(bmap);
offscreencanvas.drawBitmap(bmap, 0, 0, null);
both result in a bitmap object with width and height of -1 so when I then try and use the bitmap as a texture, it doesn’t show. I call the bitmap saving code in a button click, after the mapview has rendered but it still gives the same result.
Has anyone managed to do this?
I encountered similar problems attempting to make use of the drawing cache. Some items I found that helped me:
Here is the working code I am using:
Also note that I am using an
ImageView, but I would expect the code path to be the same forMapView.Finally in the code sample that you posted, you are creating a bitmap the size of the map view. You copy this bitmap and then throw the result away. Then you set your canvas to be backed by this bitmap, and then you try to draw the bitmap to the bitmap. (Yes I typed that correctly.) Try something like this, in place of your canvas code