mapbox-gl-native icon indicating copy to clipboard operation
mapbox-gl-native copied to clipboard

How to take a screenshot of mapview in a Android App?

Open zhangkaiyue0701 opened this issue 10 years ago • 3 comments

I want to take a screenshot of mapview, just mapview. I use getDrawingCache(), but the part of mapview is black.

zhangkaiyue0701 avatar Aug 18 '16 07:08 zhangkaiyue0701

@zhangkaiyue0701 This is because our map is using TextureView (<=v4.2.0) or a SurfaceView (v=4.2.0-beta.1). If you want to make a screenshot/snapshot of the currently displayed map use mapboxMap#snapshot. This method will return a bitmap of the shown map content. Here is an example with an onClickListener and an ImageView:

   @Override
    public void onClick(View v) {
        mapboxMap.snapshot(new MapboxMap.SnapshotReadyCallback() {
            @Override
            public void onSnapshotReady(Bitmap snapshot) {
                ImageView snapshotView = (ImageView) findViewById(R.id.imageView);
                snapshotView.setImageBitmap(snapshot);
            }
        });
    }

Thank you for requesting help, feel free to reach out again. Above code snippet should resolve your issue. Closing.

tobrun avatar Aug 18 '16 08:08 tobrun

Taking a snapshot does not include the polylines in it.

lifeLessCoder avatar Jul 10 '18 16:07 lifeLessCoder

Have you guys added support for polylines or not?

saddahussain avatar Aug 06 '20 11:08 saddahussain