[android] #4850 - add non-gl content to snapshot bitmap

This commit is contained in:
Tobrun
2016-04-27 12:34:39 +02:00
parent efa654bf4d
commit 2656b5c733
3 changed files with 13 additions and 7 deletions

View File

@@ -16,6 +16,7 @@ import android.content.pm.ServiceInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.PointF;
import android.graphics.RectF;
import android.graphics.SurfaceTexture;
@@ -2542,13 +2543,18 @@ public class MapView extends FrameLayout {
@UiThread
void snapshot(@NonNull final MapboxMap.SnapshotReadyCallback callback, @Nullable final Bitmap bitmap) {
final TextureView textureView = (TextureView) findViewById(R.id.textureView);
TextureView textureView = (TextureView) findViewById(R.id.textureView);
final boolean canUseBitmap = bitmap != null && textureView.getWidth() == bitmap.getWidth() && textureView.getHeight() == bitmap.getHeight();
if (canUseBitmap) {
callback.onSnapshotReady(textureView.getBitmap(bitmap));
} else {
callback.onSnapshotReady(textureView.getBitmap());
}
setDrawingCacheEnabled(true);
Bitmap content = Bitmap.createBitmap(getDrawingCache());
setDrawingCacheEnabled(false);
Bitmap output = Bitmap.createBitmap(content.getWidth(), content.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawBitmap(canUseBitmap ? textureView.getBitmap(bitmap) : textureView.getBitmap(), 0, 0, null);
canvas.drawBitmap(content, new Matrix(), null);
callback.onSnapshotReady(output);
}
//

View File

@@ -37,7 +37,6 @@ public class SnapshotActivity extends AppCompatActivity {
}
mapView = (MapView) findViewById(R.id.mapView);
mapView.setAccessToken(getString(R.string.mapbox_access_token));
mapView.onCreate(savedInstanceState);
mapView.getMapAsync(new OnMapReadyCallback() {
@Override

View File

@@ -30,6 +30,7 @@
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
app:access_token="@string/mapbox_access_token"
app:style_url="@string/style_emerald" />
</LinearLayout>