Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i take/merge screen shot of Google map v2 and layout of xml both programmatically?

I am taking screenshot of Google Map v2 by using code of this answer which is giving me output :

enter image description here

Which is fine to take screen shot of Map

With following code i can take the screen shot of Layout with black map screen thats ok as with following code Map will black in ScreenShot

String mPath = Environment.getExternalStorageDirectory().toString()
                + "/" + "myTestScr" + System.currentTimeMillis() + ".jpeg";
Bitmap bitmap;
        View v1 = (View) findViewById(R.id.rootviewtest);
        v1.setDrawingCacheEnabled(true);
        bitmap = Bitmap.createBitmap(v1.getDrawingCache());
        v1.setDrawingCacheEnabled(false);

        OutputStream fout = null;
        File imageFile = new File(mPath);

        try {
            fout = new FileOutputStream(imageFile);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fout);
            fout.flush();
            fout.close();

        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

output of above code:

enter image description here

What I actually need is:

enter image description here

So, Now My question that how can get the output like in 3rd Screen programmatically?

Help me to take one screen shot by merging both (1 and 2) screens programmatically?

or any other alternate to merge both images programmatically after taking both ( 1 and 2 ) screen shots ?

like image 769
Tarsem Singh Avatar asked Aug 19 '13 08:08

Tarsem Singh


People also ask

How do I capture a screenshot of Google Maps?

Open the Google Maps app on your Android phone or tablet. Browse the app to find the area you want to capture. When you're ready to take a screenshot, press the Power and Volume Down buttons together at the same time. The screenshot should be automatically generated and saved in a Screenshots folder in your Gallery.

How do I take a screenshot of Google Maps on Android?

Press the Power and Volume down buttons at the same time. If that doesn't work, press and hold the Power button for a few seconds. Then tap Screenshot.


1 Answers

Call the following method to take the screenshot with map:

public void captureMapScreen() {
        SnapshotReadyCallback callback = new SnapshotReadyCallback() {

            @Override
            public void onSnapshotReady(Bitmap snapshot) {
                try {
                    mView.setDrawingCacheEnabled(true);
                    Bitmap backBitmap = mView.getDrawingCache();
                    Bitmap bmOverlay = Bitmap.createBitmap(
                            backBitmap.getWidth(), backBitmap.getHeight(),
                            backBitmap.getConfig());
                    Canvas canvas = new Canvas(bmOverlay);
                    canvas.drawBitmap(snapshot, new Matrix(), null);
                    canvas.drawBitmap(backBitmap, 0, 0, null);
                    FileOutputStream out = new FileOutputStream(
                            Environment.getExternalStorageDirectory()
                                    + "/MapScreenShot"
                                    + System.currentTimeMillis() + ".png");

                    bmOverlay.compress(Bitmap.CompressFormat.PNG, 90, out);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        mMap.snapshot(callback);

    }

mview is the root view of your layout and mMap is your map fragment.

Make sure that you have the latest Google Play Services API.

mView.setDrawingCacheEnabled(true);
Bitmap backBitmap = mView.getDrawingCache();
Bitmap bmOverlay = Bitmap.createBitmap(
backBitmap.getWidth(), backBitmap.getHeight(),
backBitmap.getConfig());
Canvas canvas = new Canvas(bmOverlay);
canvas.drawBitmap(snapshot, new Matrix(), null);
canvas.drawBitmap(backBitmap, 0, 0, null);

Skip these lines and use snapshot.compress(Bitmap.CompressFormat.PNG, 90, out); if you want the screenshot of map only.

like image 60
JiTHiN Avatar answered Oct 20 '22 11:10

JiTHiN