To take a snapshot you wait for the map to load then take a snapshot.
details: implement SnapshotReadyCallback and OnMapLoadedCallback.
import com.google.android.gms.maps.GoogleMap.SnapshotReadyCallback;
import com.google.android.gms.maps.GoogleMap.OnMapLoadedCallback;
public class KmlReader extends ActionBarActivity implements
SnapshotReadyCallback,
OnMapLoadedCallback {
...
if (mMap == null) {
// Try to obtain the map from the SupportMapFragment.
// mMap = mMapFragment.getMap();
// // Check if we were successful in obtaining the map.
// Try to obtain the map from the SupportMapFragment.
mMap = ((SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map)).getMap();
// use the settings maptype
// Check if we were successful in obtaining the map.
if (mMap != null) {
mMap.setOnMapLoadedCallback(this);
...
@Override
public void onMapLoaded() {
if (mMap != null) {
mMap.snapshot(this);
}
}
You have a real bitmap when this fires.
@Override
public void onSnapshotReady(Bitmap bm) {
if (CheckStorage.isExternalStorageWritable()) {
int newHeight = 96;
int newWidth = 96;
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;
float scaleHeight = ((float) newHeight) / height;
// create a matrix for the manipulation
Matrix matrix = new Matrix();
// resize the bit map
matrix.postScale(scaleWidth, scaleHeight);
// recreate the new Bitmap
Bitmap resizedBitmap = Bitmap.createBitmap(bm, 0, 0, width, height,
matrix, false);